mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into LSAPICleanup
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+589
-208
File diff suppressed because it is too large
Load Diff
+58
-30
@@ -1069,7 +1069,7 @@ module ts {
|
||||
* Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope
|
||||
* Meaning needs to be specified if the enclosing declaration is given
|
||||
*/
|
||||
function buildSymbolDisplay(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void {
|
||||
function buildSymbolDisplay(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags, typeFlags?: TypeFormatFlags): void {
|
||||
var parentSymbol: Symbol;
|
||||
function appendParentTypeArgumentsAndSymbolName(symbol: Symbol): void {
|
||||
if (parentSymbol) {
|
||||
@@ -1131,11 +1131,12 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
// Get qualified name
|
||||
if (enclosingDeclaration &&
|
||||
// TypeParameters do not need qualification
|
||||
!(symbol.flags & SymbolFlags.TypeParameter)) {
|
||||
|
||||
// Get qualified name if the symbol is not a type parameter
|
||||
// and there is an enclosing declaration or we specifically
|
||||
// asked for it
|
||||
var isTypeParameter = symbol.flags & SymbolFlags.TypeParameter;
|
||||
var typeFormatFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags;
|
||||
if (!isTypeParameter && (enclosingDeclaration || typeFormatFlag)) {
|
||||
walkSymbol(symbol, meaning);
|
||||
return;
|
||||
}
|
||||
@@ -1158,7 +1159,8 @@ module ts {
|
||||
writeTypeReference(<TypeReference>type, flags);
|
||||
}
|
||||
else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) {
|
||||
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type);
|
||||
// The specified symbol flags need to be reinterpreted as type flags
|
||||
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags);
|
||||
}
|
||||
else if (type.flags & TypeFlags.Tuple) {
|
||||
writeTupleType(<TupleType>type);
|
||||
@@ -1229,17 +1231,18 @@ module ts {
|
||||
function writeAnonymousType(type: ObjectType, flags: TypeFormatFlags) {
|
||||
// Always use 'typeof T' for type of class, enum, and module objects
|
||||
if (type.symbol && type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) {
|
||||
writeTypeofSymbol(type);
|
||||
writeTypeofSymbol(type, flags);
|
||||
}
|
||||
// Use 'typeof T' for types of functions and methods that circularly reference themselves
|
||||
else if (shouldWriteTypeOfFunctionSymbol()) {
|
||||
writeTypeofSymbol(type);
|
||||
writeTypeofSymbol(type, flags);
|
||||
}
|
||||
else if (typeStack && contains(typeStack, type)) {
|
||||
// If type is an anonymous type literal in a type alias declaration, use type alias name
|
||||
var typeAlias = getTypeAliasForTypeLiteral(type);
|
||||
if (typeAlias) {
|
||||
buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type);
|
||||
// The specified symbol flags need to be reinterpreted as type flags
|
||||
buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags);
|
||||
}
|
||||
else {
|
||||
// Recursive usage, use any
|
||||
@@ -1273,10 +1276,10 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function writeTypeofSymbol(type: ObjectType) {
|
||||
function writeTypeofSymbol(type: ObjectType, typeFormatFlags?: TypeFormatFlags) {
|
||||
writeKeyword(writer, SyntaxKind.TypeOfKeyword);
|
||||
writeSpace(writer);
|
||||
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value);
|
||||
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, SymbolFormatFlags.None, typeFormatFlags);
|
||||
}
|
||||
|
||||
function getIndexerParameterName(type: ObjectType, indexKind: IndexKind, fallbackName: string): string {
|
||||
@@ -3562,7 +3565,13 @@ module ts {
|
||||
}
|
||||
if (reportErrors) {
|
||||
headMessage = headMessage || Diagnostics.Type_0_is_not_assignable_to_type_1;
|
||||
reportError(headMessage, typeToString(source), typeToString(target));
|
||||
var sourceType = typeToString(source);
|
||||
var targetType = typeToString(target);
|
||||
if (sourceType === targetType) {
|
||||
sourceType = typeToString(source, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
|
||||
targetType = typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
|
||||
}
|
||||
reportError(headMessage, sourceType, targetType);
|
||||
}
|
||||
return Ternary.False;
|
||||
}
|
||||
@@ -4331,6 +4340,9 @@ module ts {
|
||||
}
|
||||
|
||||
function inferFromTypes(source: Type, target: Type) {
|
||||
if (source === anyFunctionType) {
|
||||
return;
|
||||
}
|
||||
if (target.flags & TypeFlags.TypeParameter) {
|
||||
// If target is a type parameter, make an inference
|
||||
var typeParameters = context.typeParameters;
|
||||
@@ -4849,6 +4861,16 @@ module ts {
|
||||
function checkIdentifier(node: Identifier): Type {
|
||||
var symbol = getResolvedSymbol(node);
|
||||
|
||||
// As noted in ECMAScript 6 language spec, arrow functions never have an arguments objects.
|
||||
// Although in down-level emit of arrow function, we emit it using function expression which means that
|
||||
// arguments objects will be bound to the inner object; emitting arrow function natively in ES6, arguments objects
|
||||
// will be bound to non-arrow function that contain this arrow function. This results in inconsistent behavior.
|
||||
// To avoid that we will give an error to users if they use arguments objects in arrow function so that they
|
||||
// can explicitly bound arguments objects
|
||||
if (symbol === argumentsSymbol && getContainingFunction(node).kind === SyntaxKind.ArrowFunction) {
|
||||
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression);
|
||||
}
|
||||
|
||||
if (symbol.flags & SymbolFlags.Import) {
|
||||
var symbolLinks = getSymbolLinks(symbol);
|
||||
if (!symbolLinks.referenced) {
|
||||
@@ -4903,7 +4925,9 @@ module ts {
|
||||
// Now skip arrow functions to get the "real" owner of 'this'.
|
||||
if (container.kind === SyntaxKind.ArrowFunction) {
|
||||
container = getThisContainer(container, /* includeArrowFunctions */ false);
|
||||
needToCaptureLexicalThis = true;
|
||||
|
||||
// When targeting es6, arrow function lexically bind "this" so we do not need to do the work of binding "this" in emitted code
|
||||
needToCaptureLexicalThis = (languageVersion < ScriptTarget.ES6);
|
||||
}
|
||||
|
||||
switch (container.kind) {
|
||||
@@ -5895,28 +5919,31 @@ module ts {
|
||||
return getSignatureInstantiation(signature, getInferredTypes(context));
|
||||
}
|
||||
|
||||
function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument?: boolean[]): InferenceContext {
|
||||
function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument: boolean[]): InferenceContext {
|
||||
var typeParameters = signature.typeParameters;
|
||||
var context = createInferenceContext(typeParameters, /*inferUnionTypes*/ false);
|
||||
var mapper = createInferenceMapper(context);
|
||||
// First infer from arguments that are not context sensitive
|
||||
var inferenceMapper = createInferenceMapper(context);
|
||||
|
||||
// We perform two passes over the arguments. In the first pass we infer from all arguments, but use
|
||||
// wildcards for all context sensitive function expressions.
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (args[i].kind === SyntaxKind.OmittedExpression) {
|
||||
continue;
|
||||
}
|
||||
if (!excludeArgument || excludeArgument[i] === undefined) {
|
||||
var parameterType = getTypeAtPosition(signature, i);
|
||||
|
||||
if (i === 0 && args[i].parent.kind === SyntaxKind.TaggedTemplateExpression) {
|
||||
inferTypes(context, globalTemplateStringsArrayType, parameterType);
|
||||
continue;
|
||||
}
|
||||
|
||||
inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType);
|
||||
var parameterType = getTypeAtPosition(signature, i);
|
||||
if (i === 0 && args[i].parent.kind === SyntaxKind.TaggedTemplateExpression) {
|
||||
inferTypes(context, globalTemplateStringsArrayType, parameterType);
|
||||
continue;
|
||||
}
|
||||
// For context sensitive arguments we pass the identityMapper, which is a signal to treat all
|
||||
// context sensitive function expressions as wildcards
|
||||
var mapper = excludeArgument && excludeArgument[i] !== undefined ? identityMapper : inferenceMapper;
|
||||
inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType);
|
||||
}
|
||||
|
||||
// Next, infer from those context sensitive arguments that are no longer excluded
|
||||
// In the second pass we visit only context sensitive arguments, and only those that aren't excluded, this
|
||||
// time treating function expressions normally (which may cause previously inferred type arguments to be fixed
|
||||
// as we construct types for contextually typed parameters)
|
||||
if (excludeArgument) {
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (args[i].kind === SyntaxKind.OmittedExpression) {
|
||||
@@ -5925,10 +5952,11 @@ module ts {
|
||||
// No need to special-case tagged templates; their excludeArgument value will be 'undefined'.
|
||||
if (excludeArgument[i] === false) {
|
||||
var parameterType = getTypeAtPosition(signature, i);
|
||||
inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, mapper), parameterType);
|
||||
inferTypes(context, checkExpressionWithContextualType(args[i], parameterType, inferenceMapper), parameterType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var inferredTypes = getInferredTypes(context);
|
||||
// Inference has failed if the inferenceFailureType type is in list of inferences
|
||||
context.failedTypeParameterIndex = indexOf(inferredTypes, inferenceFailureType);
|
||||
@@ -6622,7 +6650,7 @@ module ts {
|
||||
}
|
||||
|
||||
// The identityMapper object is used to indicate that function expressions are wildcards
|
||||
if (contextualMapper === identityMapper) {
|
||||
if (contextualMapper === identityMapper && isContextSensitive(node)) {
|
||||
return anyFunctionType;
|
||||
}
|
||||
var links = getNodeLinks(node);
|
||||
@@ -7296,7 +7324,7 @@ module ts {
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
return checkTypeAssertion(<TypeAssertion>node);
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
return checkExpression((<ParenthesizedExpression>node).expression);
|
||||
return checkExpression((<ParenthesizedExpression>node).expression, contextualMapper);
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return checkFunctionExpressionOrObjectLiteralMethod(<FunctionExpression>node, contextualMapper);
|
||||
|
||||
@@ -452,5 +452,6 @@ module ts {
|
||||
You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." },
|
||||
yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported.", isEarly: true },
|
||||
Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported.", isEarly: true },
|
||||
The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." },
|
||||
};
|
||||
}
|
||||
@@ -1612,7 +1612,7 @@
|
||||
"Property '{0}' does not exist on 'const' enum '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4088,
|
||||
"isEarly": true
|
||||
"isEarly": true
|
||||
},
|
||||
"The current host does not support the '{0}' option.": {
|
||||
"category": "Error",
|
||||
@@ -1902,11 +1902,15 @@
|
||||
"'yield' expressions are not currently supported.": {
|
||||
"category": "Error",
|
||||
"code": 9000,
|
||||
"isEarly": true
|
||||
"isEarly": true
|
||||
},
|
||||
"Generators are not currently supported.": {
|
||||
"category": "Error",
|
||||
"code": 9001,
|
||||
"isEarly": true
|
||||
"isEarly": true
|
||||
},
|
||||
"The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.": {
|
||||
"category": "Error",
|
||||
"code": 9002
|
||||
}
|
||||
}
|
||||
|
||||
+31
-3
@@ -1487,7 +1487,6 @@ module ts {
|
||||
|
||||
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature
|
||||
export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile?: SourceFile): EmitResult {
|
||||
// var program = resolver.getProgram();
|
||||
var compilerOptions = host.getCompilerOptions();
|
||||
var languageVersion = compilerOptions.target || ScriptTarget.ES3;
|
||||
var sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap ? [] : undefined;
|
||||
@@ -3240,6 +3239,10 @@ module ts {
|
||||
emitSignatureAndBody(node);
|
||||
}
|
||||
|
||||
function shouldEmitAsArrowFunction(node: FunctionLikeDeclaration): boolean {
|
||||
return node.kind === SyntaxKind.ArrowFunction && languageVersion >= ScriptTarget.ES6;
|
||||
}
|
||||
|
||||
function emitFunctionDeclaration(node: FunctionLikeDeclaration) {
|
||||
if (nodeIsMissing(node.body)) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
@@ -3249,7 +3252,13 @@ module ts {
|
||||
// Methods will emit the comments as part of emitting method declaration
|
||||
emitLeadingComments(node);
|
||||
}
|
||||
write("function ");
|
||||
|
||||
// For targeting below es6, emit functions-like declaration including arrow function using function keyword.
|
||||
// When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead
|
||||
if (!shouldEmitAsArrowFunction(node)) {
|
||||
write("function ");
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.FunctionDeclaration || (node.kind === SyntaxKind.FunctionExpression && node.name)) {
|
||||
emit(node.name);
|
||||
}
|
||||
@@ -3280,6 +3289,15 @@ module ts {
|
||||
decreaseIndent();
|
||||
}
|
||||
|
||||
function emitSignatureParametersForArrow(node: FunctionLikeDeclaration) {
|
||||
// Check whether the parameter list needs parentheses and preserve no-parenthesis
|
||||
if (node.parameters.length === 1 && node.pos === node.parameters[0].pos) {
|
||||
emit(node.parameters[0]);
|
||||
return;
|
||||
}
|
||||
emitSignatureParameters(node);
|
||||
}
|
||||
|
||||
function emitSignatureAndBody(node: FunctionLikeDeclaration) {
|
||||
var saveTempCount = tempCount;
|
||||
var saveTempVariables = tempVariables;
|
||||
@@ -3287,7 +3305,16 @@ module ts {
|
||||
tempCount = 0;
|
||||
tempVariables = undefined;
|
||||
tempParameters = undefined;
|
||||
emitSignatureParameters(node);
|
||||
|
||||
// When targeting ES6, emit arrow function natively in ES6
|
||||
if (shouldEmitAsArrowFunction(node)) {
|
||||
emitSignatureParametersForArrow(node);
|
||||
write(" =>");
|
||||
}
|
||||
else {
|
||||
emitSignatureParameters(node);
|
||||
}
|
||||
|
||||
write(" {");
|
||||
scopeEmitStart(node);
|
||||
increaseIndent();
|
||||
@@ -3299,6 +3326,7 @@ module ts {
|
||||
startIndex = emitDirectivePrologues((<Block>node.body).statements, /*startWithNewLine*/ true);
|
||||
}
|
||||
var outPos = writer.getTextPos();
|
||||
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
emitDefaultValueAssignments(node);
|
||||
emitRestParameter(node);
|
||||
|
||||
@@ -1080,6 +1080,7 @@ module ts {
|
||||
WriteOwnNameForAnyLike = 0x00000010, // Write symbol's own name instead of 'any' for any like types (eg. unknown, __resolving__ etc)
|
||||
WriteTypeArgumentsOfSignature = 0x00000020, // Write the type arguments instead of type parameters of the signature
|
||||
InElementType = 0x00000040, // Writing an array or union element type
|
||||
UseFullyQualifiedType = 0x00000080, // Write out the fully qualified type name (eg. Module.Type, instead of Type)
|
||||
}
|
||||
|
||||
export const enum SymbolFormatFlags {
|
||||
|
||||
@@ -107,7 +107,7 @@ module Utils {
|
||||
export function memoize<T extends Function>(f: T): T {
|
||||
var cache: { [idx: string]: any } = {};
|
||||
|
||||
return <any>(() => {
|
||||
return <any>(function () {
|
||||
var key = Array.prototype.join.call(arguments);
|
||||
var cachedResult = cache[key];
|
||||
if (cachedResult) {
|
||||
|
||||
@@ -138,7 +138,7 @@ module Playback {
|
||||
|
||||
function recordReplay<T extends Function>(original: T, underlying: any) {
|
||||
function createWrapper(record: T, replay: T): T {
|
||||
return <any>(() => {
|
||||
return <any>(function () {
|
||||
if (replayLog !== undefined) {
|
||||
return replay.apply(undefined, arguments);
|
||||
} else if (recordLog !== undefined) {
|
||||
|
||||
@@ -186,7 +186,7 @@ class ProjectRunner extends RunnerBase {
|
||||
function createCompilerHost(): ts.CompilerHost {
|
||||
return {
|
||||
getSourceFile,
|
||||
getDefaultLibFilename: options => options.target === ts.ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts",
|
||||
getDefaultLibFilename: options => Harness.Compiler.defaultLibFileName,
|
||||
writeFile,
|
||||
getCurrentDirectory,
|
||||
getCanonicalFileName: Harness.Compiler.getCanonicalFileName,
|
||||
|
||||
@@ -867,6 +867,7 @@ declare module "typescript" {
|
||||
WriteOwnNameForAnyLike = 16,
|
||||
WriteTypeArgumentsOfSignature = 32,
|
||||
InElementType = 64,
|
||||
UseFullyQualifiedType = 128,
|
||||
}
|
||||
const enum SymbolFormatFlags {
|
||||
None = 0,
|
||||
|
||||
@@ -2829,6 +2829,9 @@ declare module "typescript" {
|
||||
|
||||
InElementType = 64,
|
||||
>InElementType : TypeFormatFlags
|
||||
|
||||
UseFullyQualifiedType = 128,
|
||||
>UseFullyQualifiedType : TypeFormatFlags
|
||||
}
|
||||
const enum SymbolFormatFlags {
|
||||
>SymbolFormatFlags : SymbolFormatFlags
|
||||
|
||||
@@ -896,6 +896,7 @@ declare module "typescript" {
|
||||
WriteOwnNameForAnyLike = 16,
|
||||
WriteTypeArgumentsOfSignature = 32,
|
||||
InElementType = 64,
|
||||
UseFullyQualifiedType = 128,
|
||||
}
|
||||
const enum SymbolFormatFlags {
|
||||
None = 0,
|
||||
|
||||
@@ -2959,6 +2959,9 @@ declare module "typescript" {
|
||||
|
||||
InElementType = 64,
|
||||
>InElementType : TypeFormatFlags
|
||||
|
||||
UseFullyQualifiedType = 128,
|
||||
>UseFullyQualifiedType : TypeFormatFlags
|
||||
}
|
||||
const enum SymbolFormatFlags {
|
||||
>SymbolFormatFlags : SymbolFormatFlags
|
||||
|
||||
@@ -897,6 +897,7 @@ declare module "typescript" {
|
||||
WriteOwnNameForAnyLike = 16,
|
||||
WriteTypeArgumentsOfSignature = 32,
|
||||
InElementType = 64,
|
||||
UseFullyQualifiedType = 128,
|
||||
}
|
||||
const enum SymbolFormatFlags {
|
||||
None = 0,
|
||||
|
||||
@@ -2907,6 +2907,9 @@ declare module "typescript" {
|
||||
|
||||
InElementType = 64,
|
||||
>InElementType : TypeFormatFlags
|
||||
|
||||
UseFullyQualifiedType = 128,
|
||||
>UseFullyQualifiedType : TypeFormatFlags
|
||||
}
|
||||
const enum SymbolFormatFlags {
|
||||
>SymbolFormatFlags : SymbolFormatFlags
|
||||
|
||||
@@ -934,6 +934,7 @@ declare module "typescript" {
|
||||
WriteOwnNameForAnyLike = 16,
|
||||
WriteTypeArgumentsOfSignature = 32,
|
||||
InElementType = 64,
|
||||
UseFullyQualifiedType = 128,
|
||||
}
|
||||
const enum SymbolFormatFlags {
|
||||
None = 0,
|
||||
|
||||
@@ -3085,6 +3085,9 @@ declare module "typescript" {
|
||||
|
||||
InElementType = 64,
|
||||
>InElementType : TypeFormatFlags
|
||||
|
||||
UseFullyQualifiedType = 128,
|
||||
>UseFullyQualifiedType : TypeFormatFlags
|
||||
}
|
||||
const enum SymbolFormatFlags {
|
||||
>SymbolFormatFlags : SymbolFormatFlags
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
tests/cases/compiler/clodulesDerivedClasses.ts(9,7): error TS2417: Class static side 'typeof Path' incorrectly extends base class static side 'typeof Shape'.
|
||||
Types of property 'Utils' are incompatible.
|
||||
Type 'typeof Utils' is not assignable to type 'typeof Utils'.
|
||||
Type 'typeof Path.Utils' is not assignable to type 'typeof Shape.Utils'.
|
||||
Property 'convert' is missing in type 'typeof Utils'.
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ tests/cases/compiler/clodulesDerivedClasses.ts(9,7): error TS2417: Class static
|
||||
~~~~
|
||||
!!! error TS2417: Class static side 'typeof Path' incorrectly extends base class static side 'typeof Shape'.
|
||||
!!! error TS2417: Types of property 'Utils' are incompatible.
|
||||
!!! error TS2417: Type 'typeof Utils' is not assignable to type 'typeof Utils'.
|
||||
!!! error TS2417: Type 'typeof Path.Utils' is not assignable to type 'typeof Shape.Utils'.
|
||||
!!! error TS2417: Property 'convert' is missing in type 'typeof Utils'.
|
||||
name: string;
|
||||
|
||||
|
||||
@@ -15,10 +15,9 @@ var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.bar = function () {
|
||||
var _this = this;
|
||||
(function () {
|
||||
(() => {
|
||||
var obj = {
|
||||
[_this.bar()]() {
|
||||
[this.bar()]() {
|
||||
} // needs capture
|
||||
};
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ var C = (function () {
|
||||
}
|
||||
C.prototype[0 + 1] = function () {
|
||||
};
|
||||
C[function () {
|
||||
C[() => {
|
||||
}] = function () {
|
||||
};
|
||||
Object.defineProperty(C.prototype, delete id, {
|
||||
|
||||
@@ -31,7 +31,7 @@ var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
_super.call(this);
|
||||
(function () {
|
||||
(() => {
|
||||
var obj = {
|
||||
// Ideally, we would capture this. But the reference is
|
||||
// illegal, and not capturing this is consistent with
|
||||
|
||||
@@ -37,7 +37,7 @@ var C = (function (_super) {
|
||||
}
|
||||
C.prototype.foo = function () {
|
||||
var _this = this;
|
||||
(function () {
|
||||
(() => {
|
||||
var obj = {
|
||||
[_super.prototype.bar.call(_this)]() {
|
||||
} // needs capture
|
||||
|
||||
@@ -14,5 +14,5 @@ var o = {
|
||||
["" + 0](y) {
|
||||
return y.length;
|
||||
},
|
||||
["" + 1]: function (y) { return y.length; }
|
||||
["" + 1]: y => { return y.length; }
|
||||
};
|
||||
|
||||
@@ -14,5 +14,5 @@ var o = {
|
||||
[+"foo"](y) {
|
||||
return y.length;
|
||||
},
|
||||
[+"bar"]: function (y) { return y.length; }
|
||||
[+"bar"]: y => { return y.length; }
|
||||
};
|
||||
|
||||
@@ -13,5 +13,5 @@ var o = {
|
||||
[+"foo"](y) {
|
||||
return y.length;
|
||||
},
|
||||
[+"bar"]: function (y) { return y.length; }
|
||||
[+"bar"]: y => { return y.length; }
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ foo({
|
||||
//// [computedPropertyNamesContextualType6.js]
|
||||
foo({
|
||||
p: "",
|
||||
0: function () {
|
||||
0: () => {
|
||||
},
|
||||
["hi" + "bye"]: true,
|
||||
[0 + 1]: 0,
|
||||
|
||||
@@ -16,7 +16,7 @@ foo({
|
||||
//// [computedPropertyNamesContextualType7.js]
|
||||
foo({
|
||||
p: "",
|
||||
0: function () {
|
||||
0: () => {
|
||||
},
|
||||
["hi" + "bye"]: true,
|
||||
[0 + 1]: 0,
|
||||
|
||||
@@ -223,7 +223,7 @@ function F() {
|
||||
const c = 0;
|
||||
n = c;
|
||||
}
|
||||
var F2 = function () {
|
||||
var F2 = () => {
|
||||
const c = 0;
|
||||
n = c;
|
||||
};
|
||||
@@ -272,7 +272,7 @@ var o = {
|
||||
const c = 0;
|
||||
n = c;
|
||||
},
|
||||
f2: function () {
|
||||
f2: () => {
|
||||
const c = 0;
|
||||
n = c;
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ const c18 = 0;
|
||||
function F() {
|
||||
const c19 = 0;
|
||||
}
|
||||
var F2 = function () {
|
||||
var F2 = () => {
|
||||
const c20 = 0;
|
||||
};
|
||||
var F3 = function () {
|
||||
@@ -226,7 +226,7 @@ var o = {
|
||||
f() {
|
||||
const c28 = 0;
|
||||
},
|
||||
f2: function () {
|
||||
f2: () => {
|
||||
const c29 = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(2,22): error TS2339: Property 'foo' does not exist on type 'string'.
|
||||
tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
|
||||
Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'T'.
|
||||
tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,32): error TS2339: Property 'foo' does not exist on type 'T'.
|
||||
tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,32): error TS2339: Property 'foo' does not exist on type 'string'.
|
||||
tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,38): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (3 errors) ====
|
||||
@@ -10,8 +9,7 @@ tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,32): error TS
|
||||
~~~
|
||||
!!! error TS2339: Property 'foo' does not exist on type 'string'.
|
||||
var r9 = f10('', () => (a => a.foo), 1); // error
|
||||
~~~
|
||||
!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
|
||||
!!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'T'.
|
||||
~~~
|
||||
!!! error TS2339: Property 'foo' does not exist on type 'T'.
|
||||
!!! error TS2339: Property 'foo' does not exist on type 'string'.
|
||||
~
|
||||
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
|
||||
@@ -0,0 +1,24 @@
|
||||
tests/cases/compiler/differentTypesWithSameName.ts(16,15): error TS2345: Argument of type 'variable' is not assignable to parameter of type 'm.variable'.
|
||||
Property 's' is missing in type 'variable'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/differentTypesWithSameName.ts (1 errors) ====
|
||||
module m {
|
||||
export class variable{
|
||||
s: string;
|
||||
}
|
||||
export function doSomething(v: m.variable) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class variable {
|
||||
t: number;
|
||||
}
|
||||
|
||||
|
||||
var v: variable = new variable();
|
||||
m.doSomething(v);
|
||||
~
|
||||
!!! error TS2345: Argument of type 'variable' is not assignable to parameter of type 'm.variable'.
|
||||
!!! error TS2345: Property 's' is missing in type 'variable'.
|
||||
@@ -0,0 +1,38 @@
|
||||
//// [differentTypesWithSameName.ts]
|
||||
module m {
|
||||
export class variable{
|
||||
s: string;
|
||||
}
|
||||
export function doSomething(v: m.variable) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class variable {
|
||||
t: number;
|
||||
}
|
||||
|
||||
|
||||
var v: variable = new variable();
|
||||
m.doSomething(v);
|
||||
|
||||
//// [differentTypesWithSameName.js]
|
||||
var m;
|
||||
(function (m) {
|
||||
var variable = (function () {
|
||||
function variable() {
|
||||
}
|
||||
return variable;
|
||||
})();
|
||||
m.variable = variable;
|
||||
function doSomething(v) {
|
||||
}
|
||||
m.doSomething = doSomething;
|
||||
})(m || (m = {}));
|
||||
var variable = (function () {
|
||||
function variable() {
|
||||
}
|
||||
return variable;
|
||||
})();
|
||||
var v = new variable();
|
||||
m.doSomething(v);
|
||||
@@ -0,0 +1,29 @@
|
||||
//// [emitArrowFunction.ts]
|
||||
var f1 = () => { }
|
||||
var f2 = (x: string, y: string) => { }
|
||||
var f3 = (x: string, y: number, ...rest) => { }
|
||||
var f4 = (x: string, y: number, z = 10) => { }
|
||||
function foo(func: () => boolean) { }
|
||||
foo(() => true);
|
||||
foo(() => { return false; });
|
||||
|
||||
//// [emitArrowFunction.js]
|
||||
var f1 = function () {
|
||||
};
|
||||
var f2 = function (x, y) {
|
||||
};
|
||||
var f3 = function (x, y) {
|
||||
var rest = [];
|
||||
for (var _i = 2; _i < arguments.length; _i++) {
|
||||
rest[_i - 2] = arguments[_i];
|
||||
}
|
||||
};
|
||||
var f4 = function (x, y, z) {
|
||||
if (z === void 0) { z = 10; }
|
||||
};
|
||||
function foo(func) {
|
||||
}
|
||||
foo(function () { return true; });
|
||||
foo(function () {
|
||||
return false;
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunction.ts ===
|
||||
var f1 = () => { }
|
||||
>f1 : () => void
|
||||
>() => { } : () => void
|
||||
|
||||
var f2 = (x: string, y: string) => { }
|
||||
>f2 : (x: string, y: string) => void
|
||||
>(x: string, y: string) => { } : (x: string, y: string) => void
|
||||
>x : string
|
||||
>y : string
|
||||
|
||||
var f3 = (x: string, y: number, ...rest) => { }
|
||||
>f3 : (x: string, y: number, ...rest: any[]) => void
|
||||
>(x: string, y: number, ...rest) => { } : (x: string, y: number, ...rest: any[]) => void
|
||||
>x : string
|
||||
>y : number
|
||||
>rest : any[]
|
||||
|
||||
var f4 = (x: string, y: number, z = 10) => { }
|
||||
>f4 : (x: string, y: number, z?: number) => void
|
||||
>(x: string, y: number, z = 10) => { } : (x: string, y: number, z?: number) => void
|
||||
>x : string
|
||||
>y : number
|
||||
>z : number
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
>foo : (func: () => boolean) => void
|
||||
>func : () => boolean
|
||||
|
||||
foo(() => true);
|
||||
>foo(() => true) : void
|
||||
>foo : (func: () => boolean) => void
|
||||
>() => true : () => boolean
|
||||
|
||||
foo(() => { return false; });
|
||||
>foo(() => { return false; }) : void
|
||||
>foo : (func: () => boolean) => void
|
||||
>() => { return false; } : () => boolean
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [emitArrowFunctionAsIs.ts]
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
|
||||
//// [emitArrowFunctionAsIs.js]
|
||||
var arrow1 = function (a) {
|
||||
};
|
||||
var arrow2 = function (a) {
|
||||
};
|
||||
var arrow3 = function (a, b) {
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionAsIs.ts ===
|
||||
var arrow1 = a => { };
|
||||
>arrow1 : (a: any) => void
|
||||
>a => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow2 = (a) => { };
|
||||
>arrow2 : (a: any) => void
|
||||
>(a) => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
>arrow3 : (a: any, b: any) => void
|
||||
>(a, b) => { } : (a: any, b: any) => void
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [emitArrowFunctionAsIsES6.ts]
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
|
||||
//// [emitArrowFunctionAsIsES6.js]
|
||||
var arrow1 = a => {
|
||||
};
|
||||
var arrow2 = (a) => {
|
||||
};
|
||||
var arrow3 = (a, b) => {
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionAsIsES6.ts ===
|
||||
var arrow1 = a => { };
|
||||
>arrow1 : (a: any) => void
|
||||
>a => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow2 = (a) => { };
|
||||
>arrow2 : (a: any) => void
|
||||
>(a) => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
>arrow3 : (a: any, b: any) => void
|
||||
>(a, b) => { } : (a: any, b: any) => void
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
//// [emitArrowFunctionES6.ts]
|
||||
var f1 = () => { }
|
||||
var f2 = (x: string, y: string) => { }
|
||||
var f3 = (x: string, y: number, ...rest) => { }
|
||||
var f4 = (x: string, y: number, z=10) => { }
|
||||
function foo(func: () => boolean) { }
|
||||
foo(() => true);
|
||||
foo(() => { return false; });
|
||||
|
||||
|
||||
//// [emitArrowFunctionES6.js]
|
||||
var f1 = () => {
|
||||
};
|
||||
var f2 = (x, y) => {
|
||||
};
|
||||
var f3 = (x, y, ...rest) => {
|
||||
};
|
||||
var f4 = (x, y, z = 10) => {
|
||||
};
|
||||
function foo(func) {
|
||||
}
|
||||
foo(() => { return true; });
|
||||
foo(() => {
|
||||
return false;
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionES6.ts ===
|
||||
var f1 = () => { }
|
||||
>f1 : () => void
|
||||
>() => { } : () => void
|
||||
|
||||
var f2 = (x: string, y: string) => { }
|
||||
>f2 : (x: string, y: string) => void
|
||||
>(x: string, y: string) => { } : (x: string, y: string) => void
|
||||
>x : string
|
||||
>y : string
|
||||
|
||||
var f3 = (x: string, y: number, ...rest) => { }
|
||||
>f3 : (x: string, y: number, ...rest: any[]) => void
|
||||
>(x: string, y: number, ...rest) => { } : (x: string, y: number, ...rest: any[]) => void
|
||||
>x : string
|
||||
>y : number
|
||||
>rest : any[]
|
||||
|
||||
var f4 = (x: string, y: number, z=10) => { }
|
||||
>f4 : (x: string, y: number, z?: number) => void
|
||||
>(x: string, y: number, z=10) => { } : (x: string, y: number, z?: number) => void
|
||||
>x : string
|
||||
>y : number
|
||||
>z : number
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
>foo : (func: () => boolean) => void
|
||||
>func : () => boolean
|
||||
|
||||
foo(() => true);
|
||||
>foo(() => true) : void
|
||||
>foo : (func: () => boolean) => void
|
||||
>() => true : () => boolean
|
||||
|
||||
foo(() => { return false; });
|
||||
>foo(() => { return false; }) : void
|
||||
>foo : (func: () => boolean) => void
|
||||
>() => { return false; } : () => boolean
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
//// [emitArrowFunctionThisCapturing.ts]
|
||||
var f1 = () => {
|
||||
this.age = 10
|
||||
};
|
||||
|
||||
var f2 = (x: string) => {
|
||||
this.name = x
|
||||
}
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
foo(() => {
|
||||
this.age = 100;
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
//// [emitArrowFunctionThisCapturing.js]
|
||||
var _this = this;
|
||||
var f1 = function () {
|
||||
_this.age = 10;
|
||||
};
|
||||
var f2 = function (x) {
|
||||
_this.name = x;
|
||||
};
|
||||
function foo(func) {
|
||||
}
|
||||
foo(function () {
|
||||
_this.age = 100;
|
||||
return true;
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionThisCapturing.ts ===
|
||||
var f1 = () => {
|
||||
>f1 : () => void
|
||||
>() => { this.age = 10} : () => void
|
||||
|
||||
this.age = 10
|
||||
>this.age = 10 : number
|
||||
>this.age : any
|
||||
>this : any
|
||||
>age : any
|
||||
|
||||
};
|
||||
|
||||
var f2 = (x: string) => {
|
||||
>f2 : (x: string) => void
|
||||
>(x: string) => { this.name = x} : (x: string) => void
|
||||
>x : string
|
||||
|
||||
this.name = x
|
||||
>this.name = x : string
|
||||
>this.name : any
|
||||
>this : any
|
||||
>name : any
|
||||
>x : string
|
||||
}
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
>foo : (func: () => boolean) => void
|
||||
>func : () => boolean
|
||||
|
||||
foo(() => {
|
||||
>foo(() => { this.age = 100; return true;}) : void
|
||||
>foo : (func: () => boolean) => void
|
||||
>() => { this.age = 100; return true;} : () => boolean
|
||||
|
||||
this.age = 100;
|
||||
>this.age = 100 : number
|
||||
>this.age : any
|
||||
>this : any
|
||||
>age : any
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
//// [emitArrowFunctionThisCapturingES6.ts]
|
||||
var f1 = () => {
|
||||
this.age = 10
|
||||
};
|
||||
|
||||
var f2 = (x: string) => {
|
||||
this.name = x
|
||||
}
|
||||
|
||||
function foo(func: () => boolean){ }
|
||||
foo(() => {
|
||||
this.age = 100;
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
//// [emitArrowFunctionThisCapturingES6.js]
|
||||
var f1 = () => {
|
||||
this.age = 10;
|
||||
};
|
||||
var f2 = (x) => {
|
||||
this.name = x;
|
||||
};
|
||||
function foo(func) {
|
||||
}
|
||||
foo(() => {
|
||||
this.age = 100;
|
||||
return true;
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionThisCapturingES6.ts ===
|
||||
var f1 = () => {
|
||||
>f1 : () => void
|
||||
>() => { this.age = 10} : () => void
|
||||
|
||||
this.age = 10
|
||||
>this.age = 10 : number
|
||||
>this.age : any
|
||||
>this : any
|
||||
>age : any
|
||||
|
||||
};
|
||||
|
||||
var f2 = (x: string) => {
|
||||
>f2 : (x: string) => void
|
||||
>(x: string) => { this.name = x} : (x: string) => void
|
||||
>x : string
|
||||
|
||||
this.name = x
|
||||
>this.name = x : string
|
||||
>this.name : any
|
||||
>this : any
|
||||
>name : any
|
||||
>x : string
|
||||
}
|
||||
|
||||
function foo(func: () => boolean){ }
|
||||
>foo : (func: () => boolean) => void
|
||||
>func : () => boolean
|
||||
|
||||
foo(() => {
|
||||
>foo(() => { this.age = 100; return true;}) : void
|
||||
>foo : (func: () => boolean) => void
|
||||
>() => { this.age = 100; return true;} : () => boolean
|
||||
|
||||
this.age = 100;
|
||||
>this.age = 100 : number
|
||||
>this.age : any
|
||||
>this : any
|
||||
>age : any
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(2,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(7,19): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(13,13): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(19,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts (4 errors) ====
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
}
|
||||
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
}
|
||||
}
|
||||
|
||||
function baz() {
|
||||
() => {
|
||||
var arg = arguments[0];
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
}
|
||||
}
|
||||
|
||||
function foo(inputFunc: () => void) { }
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
});
|
||||
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
|
||||
|
||||
() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
//// [emitArrowFunctionWhenUsingArguments.ts]
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
}
|
||||
|
||||
function baz() {
|
||||
() => {
|
||||
var arg = arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
function foo(inputFunc: () => void) { }
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
});
|
||||
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
|
||||
|
||||
() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
}
|
||||
|
||||
//// [emitArrowFunctionWhenUsingArguments.js]
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
};
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
};
|
||||
};
|
||||
function baz() {
|
||||
(() => {
|
||||
var arg = arguments[0];
|
||||
});
|
||||
}
|
||||
function foo(inputFunc) {
|
||||
}
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
});
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
(() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(2,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(7,19): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(13,13): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(19,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts (4 errors) ====
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
}
|
||||
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
}
|
||||
}
|
||||
|
||||
function baz() {
|
||||
() => {
|
||||
var arg = arguments[0];
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
}
|
||||
}
|
||||
|
||||
function foo(inputFunc: () => void) { }
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
~~~~~~~~~
|
||||
!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
|
||||
});
|
||||
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
|
||||
|
||||
() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
//// [emitArrowFunctionWhenUsingArgumentsES6.ts]
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
}
|
||||
|
||||
function baz() {
|
||||
() => {
|
||||
var arg = arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
function foo(inputFunc: () => void) { }
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
});
|
||||
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
|
||||
|
||||
() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
}
|
||||
|
||||
//// [emitArrowFunctionWhenUsingArgumentsES6.js]
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
};
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
};
|
||||
};
|
||||
function baz() {
|
||||
(() => {
|
||||
var arg = arguments[0];
|
||||
});
|
||||
}
|
||||
function foo(inputFunc) {
|
||||
}
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
});
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
(() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [emitArrowFunctionsAsIs.ts]
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
|
||||
//// [emitArrowFunctionsAsIs.js]
|
||||
var arrow1 = function (a) {
|
||||
};
|
||||
var arrow2 = function (a) {
|
||||
};
|
||||
var arrow3 = function (a, b) {
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionsAsIs.ts ===
|
||||
var arrow1 = a => { };
|
||||
>arrow1 : (a: any) => void
|
||||
>a => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow2 = (a) => { };
|
||||
>arrow2 : (a: any) => void
|
||||
>(a) => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
>arrow3 : (a: any, b: any) => void
|
||||
>(a, b) => { } : (a: any, b: any) => void
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [emitArrowFunctionsAsIsES6.ts]
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
|
||||
//// [emitArrowFunctionsAsIsES6.js]
|
||||
var arrow1 = a => {
|
||||
};
|
||||
var arrow2 = (a) => {
|
||||
};
|
||||
var arrow3 = (a, b) => {
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionsAsIsES6.ts ===
|
||||
var arrow1 = a => { };
|
||||
>arrow1 : (a: any) => void
|
||||
>a => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow2 = (a) => { };
|
||||
>arrow2 : (a: any) => void
|
||||
>(a) => { } : (a: any) => void
|
||||
>a : any
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
>arrow3 : (a: any, b: any) => void
|
||||
>(a, b) => { } : (a: any, b: any) => void
|
||||
>a : any
|
||||
>b : any
|
||||
|
||||
@@ -9,13 +9,13 @@ var y = (function (num = 10, boo = false, ...rest) { })()
|
||||
var z = (function (num: number, boo = false, ...rest) { })(10)
|
||||
|
||||
//// [emitDefaultParametersFunctionExpressionES6.js]
|
||||
var lambda1 = function (y = "hello") {
|
||||
var lambda1 = (y = "hello") => {
|
||||
};
|
||||
var lambda2 = function (x, y = "hello") {
|
||||
var lambda2 = (x, y = "hello") => {
|
||||
};
|
||||
var lambda3 = function (x, y = "hello", ...rest) {
|
||||
var lambda3 = (x, y = "hello", ...rest) => {
|
||||
};
|
||||
var lambda4 = function (y = "hello", ...rest) {
|
||||
var lambda4 = (y = "hello", ...rest) => {
|
||||
};
|
||||
var x = function (str = "hello", ...rest) {
|
||||
};
|
||||
|
||||
@@ -5,9 +5,9 @@ var funcExp2 = function (...rest) { }
|
||||
var funcExp3 = (function (...rest) { })()
|
||||
|
||||
//// [emitRestParametersFunctionExpressionES6.js]
|
||||
var funcExp = function (...rest) {
|
||||
var funcExp = (...rest) => {
|
||||
};
|
||||
var funcExp1 = function (X, ...rest) {
|
||||
var funcExp1 = (X, ...rest) => {
|
||||
};
|
||||
var funcExp2 = function (...rest) {
|
||||
};
|
||||
|
||||
@@ -25,10 +25,10 @@ tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAnd
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(50,5): error TS2322: Type 'typeof N' is not assignable to type 'typeof M'.
|
||||
Types of property 'A' are incompatible.
|
||||
Type 'typeof A' is not assignable to type 'typeof A'.
|
||||
Type 'A' is not assignable to type 'A'.
|
||||
Type 'typeof N.A' is not assignable to type 'typeof M.A'.
|
||||
Type 'N.A' is not assignable to type 'M.A'.
|
||||
Property 'name' is missing in type 'A'.
|
||||
tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(51,5): error TS2322: Type 'A' is not assignable to type 'A'.
|
||||
tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(51,5): error TS2322: Type 'N.A' is not assignable to type 'M.A'.
|
||||
tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(52,5): error TS2322: Type '(x: number) => boolean' is not assignable to type '(x: number) => string'.
|
||||
Type 'boolean' is not assignable to type 'string'.
|
||||
|
||||
@@ -124,12 +124,12 @@ tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAnd
|
||||
~~~~~~~
|
||||
!!! error TS2322: Type 'typeof N' is not assignable to type 'typeof M'.
|
||||
!!! error TS2322: Types of property 'A' are incompatible.
|
||||
!!! error TS2322: Type 'typeof A' is not assignable to type 'typeof A'.
|
||||
!!! error TS2322: Type 'A' is not assignable to type 'A'.
|
||||
!!! error TS2322: Type 'typeof N.A' is not assignable to type 'typeof M.A'.
|
||||
!!! error TS2322: Type 'N.A' is not assignable to type 'M.A'.
|
||||
!!! error TS2322: Property 'name' is missing in type 'A'.
|
||||
var aClassInModule: M.A = new N.A();
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type 'A' is not assignable to type 'A'.
|
||||
!!! error TS2322: Type 'N.A' is not assignable to type 'M.A'.
|
||||
var aFunctionInModule: typeof M.F2 = F2;
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '(x: number) => boolean' is not assignable to type '(x: number) => string'.
|
||||
|
||||
@@ -239,7 +239,7 @@ function F() {
|
||||
let l = 0;
|
||||
n = l;
|
||||
}
|
||||
var F2 = function () {
|
||||
var F2 = () => {
|
||||
let l = 0;
|
||||
n = l;
|
||||
};
|
||||
@@ -289,7 +289,7 @@ var o = {
|
||||
let l = 0;
|
||||
n = l;
|
||||
},
|
||||
f2: function () {
|
||||
f2: () => {
|
||||
let l = 0;
|
||||
n = l;
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ let l18 = 0;
|
||||
function F() {
|
||||
let l19 = 0;
|
||||
}
|
||||
var F2 = function () {
|
||||
var F2 = () => {
|
||||
let l20 = 0;
|
||||
};
|
||||
var F3 = function () {
|
||||
@@ -246,7 +246,7 @@ var o = {
|
||||
f() {
|
||||
let l28 = 0;
|
||||
},
|
||||
f2: function () {
|
||||
f2: () => {
|
||||
let l29 = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -220,11 +220,11 @@ var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)
|
||||
>x => undefined : (x: number) => any
|
||||
>x : number
|
||||
>undefined : undefined
|
||||
>((x => x)) : (x: number) => number
|
||||
>(x => x) : (x: number) => number
|
||||
>x => x : (x: number) => number
|
||||
>x : number
|
||||
>x : number
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var lambda1: (x: number) => number = x => x;
|
||||
>lambda1 : (x: number) => number
|
||||
|
||||
@@ -25,11 +25,11 @@ var h = tempFun `${ (x => x) } ${ (((x => x))) } ${ undefined }`
|
||||
function tempFun(tempStrs, g, x) {
|
||||
return g(x);
|
||||
}
|
||||
var a = tempFun `${function (x) { return x; }} ${10}`;
|
||||
var b = tempFun `${(function (x) { return x; })} ${10}`;
|
||||
var c = tempFun `${((function (x) { return x; }))} ${10}`;
|
||||
var d = tempFun `${function (x) { return x; }} ${function (x) { return x; }} ${10}`;
|
||||
var e = tempFun `${function (x) { return x; }} ${(function (x) { return x; })} ${10}`;
|
||||
var f = tempFun `${function (x) { return x; }} ${((function (x) { return x; }))} ${10}`;
|
||||
var g = tempFun `${(function (x) { return x; })} ${(((function (x) { return x; })))} ${10}`;
|
||||
var h = tempFun `${(function (x) { return x; })} ${(((function (x) { return x; })))} ${undefined}`;
|
||||
var a = tempFun `${x => { return x; }} ${10}`;
|
||||
var b = tempFun `${(x => { return x; })} ${10}`;
|
||||
var c = tempFun `${((x => { return x; }))} ${10}`;
|
||||
var d = tempFun `${x => { return x; }} ${x => { return x; }} ${10}`;
|
||||
var e = tempFun `${x => { return x; }} ${(x => { return x; })} ${10}`;
|
||||
var f = tempFun `${x => { return x; }} ${((x => { return x; }))} ${10}`;
|
||||
var g = tempFun `${(x => { return x; })} ${(((x => { return x; })))} ${10}`;
|
||||
var h = tempFun `${(x => { return x; })} ${(((x => { return x; })))} ${undefined}`;
|
||||
|
||||
@@ -10,7 +10,7 @@ tests/cases/compiler/qualify.ts(47,13): error TS2322: Type 'I4' is not assignabl
|
||||
tests/cases/compiler/qualify.ts(48,13): error TS2322: Type 'I4' is not assignable to type '(k: I3) => void'.
|
||||
tests/cases/compiler/qualify.ts(49,13): error TS2322: Type 'I4' is not assignable to type '{ k: I3; }'.
|
||||
Property 'k' is missing in type 'I4'.
|
||||
tests/cases/compiler/qualify.ts(58,5): error TS2322: Type 'I' is not assignable to type 'I'.
|
||||
tests/cases/compiler/qualify.ts(58,5): error TS2322: Type 'I' is not assignable to type 'T.I'.
|
||||
Property 'p' is missing in type 'I'.
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ tests/cases/compiler/qualify.ts(58,5): error TS2322: Type 'I' is not assignable
|
||||
var y:I;
|
||||
var x:T.I=y;
|
||||
~
|
||||
!!! error TS2322: Type 'I' is not assignable to type 'I'.
|
||||
!!! error TS2322: Type 'I' is not assignable to type 'T.I'.
|
||||
!!! error TS2322: Property 'p' is missing in type 'I'.
|
||||
|
||||
|
||||
@@ -26,28 +26,28 @@ function tempTag1(...rest) {
|
||||
// Otherwise, the arrow functions' parameters will be typed as 'any',
|
||||
// and it is an error to invoke an any-typed value with type arguments,
|
||||
// so this test will error.
|
||||
tempTag1 `${function (x) {
|
||||
tempTag1 `${x => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${10}`;
|
||||
tempTag1 `${function (x) {
|
||||
tempTag1 `${x => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${function (y) {
|
||||
}}${y => {
|
||||
y(undefined);
|
||||
return y;
|
||||
}}${10}`;
|
||||
tempTag1 `${function (x) {
|
||||
tempTag1 `${x => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${function (y) {
|
||||
}}${(y) => {
|
||||
y(undefined);
|
||||
return y;
|
||||
}}${undefined}`;
|
||||
tempTag1 `${function (x) {
|
||||
tempTag1 `${(x) => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${function (y) {
|
||||
}}${y => {
|
||||
y(undefined);
|
||||
return y;
|
||||
}}${undefined}`;
|
||||
|
||||
@@ -25,18 +25,18 @@ function tempTag2(...rest) {
|
||||
// Otherwise, the arrow functions' parameters will be typed as 'any',
|
||||
// and it is an error to invoke an any-typed value with type arguments,
|
||||
// so this test will error.
|
||||
tempTag2 `${function (x) {
|
||||
tempTag2 `${x => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${0}`;
|
||||
tempTag2 `${function (x) {
|
||||
tempTag2 `${x => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${function (y) {
|
||||
}}${y => {
|
||||
y(null);
|
||||
return y;
|
||||
}}${"hello"}`;
|
||||
tempTag2 `${function (x) {
|
||||
tempTag2 `${x => {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${undefined}${"hello"}`;
|
||||
|
||||
@@ -111,40 +111,40 @@ someGenerics1b `${3}`;
|
||||
// Generic tag with argument of function type whose parameter is of type parameter type
|
||||
function someGenerics2a(strs, n) {
|
||||
}
|
||||
someGenerics2a `${function (n) { return n; }}`;
|
||||
someGenerics2a `${(n) => { return n; }}`;
|
||||
function someGenerics2b(strs, n) {
|
||||
}
|
||||
someGenerics2b `${function (n, x) { return n; }}`;
|
||||
someGenerics2b `${(n, x) => { return n; }}`;
|
||||
// Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter
|
||||
function someGenerics3(strs, producer) {
|
||||
}
|
||||
someGenerics3 `${function () { return ''; }}`;
|
||||
someGenerics3 `${function () { return undefined; }}`;
|
||||
someGenerics3 `${function () { return 3; }}`;
|
||||
someGenerics3 `${() => { return ''; }}`;
|
||||
someGenerics3 `${() => { return undefined; }}`;
|
||||
someGenerics3 `${() => { return 3; }}`;
|
||||
// 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type
|
||||
function someGenerics4(strs, n, f) {
|
||||
}
|
||||
someGenerics4 `${4}${function () { return null; }}`;
|
||||
someGenerics4 `${''}${function () { return 3; }}`;
|
||||
someGenerics4 `${4}${() => { return null; }}`;
|
||||
someGenerics4 `${''}${() => { return 3; }}`;
|
||||
someGenerics4 `${null}${null}`;
|
||||
// 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type
|
||||
function someGenerics5(strs, n, f) {
|
||||
}
|
||||
someGenerics5 `${4} ${function () { return null; }}`;
|
||||
someGenerics5 `${''}${function () { return 3; }}`;
|
||||
someGenerics5 `${4} ${() => { return null; }}`;
|
||||
someGenerics5 `${''}${() => { return 3; }}`;
|
||||
someGenerics5 `${null}${null}`;
|
||||
// Generic tag with multiple arguments of function types that each have parameters of the same generic type
|
||||
function someGenerics6(strs, a, b, c) {
|
||||
}
|
||||
someGenerics6 `${function (n) { return n; }}${function (n) { return n; }}${function (n) { return n; }}`;
|
||||
someGenerics6 `${function (n) { return n; }}${function (n) { return n; }}${function (n) { return n; }}`;
|
||||
someGenerics6 `${function (n) { return n; }}${function (n) { return n; }}${function (n) { return n; }}`;
|
||||
someGenerics6 `${n => { return n; }}${n => { return n; }}${n => { return n; }}`;
|
||||
someGenerics6 `${n => { return n; }}${n => { return n; }}${n => { return n; }}`;
|
||||
someGenerics6 `${(n) => { return n; }}${(n) => { return n; }}${(n) => { return n; }}`;
|
||||
// Generic tag with multiple arguments of function types that each have parameters of different generic type
|
||||
function someGenerics7(strs, a, b, c) {
|
||||
}
|
||||
someGenerics7 `${function (n) { return n; }}${function (n) { return n; }}${function (n) { return n; }}`;
|
||||
someGenerics7 `${function (n) { return n; }}${function (n) { return n; }}${function (n) { return n; }}`;
|
||||
someGenerics7 `${function (n) { return n; }}${function (n) { return n; }}${function (n) { return n; }}`;
|
||||
someGenerics7 `${n => { return n; }}${n => { return n; }}${n => { return n; }}`;
|
||||
someGenerics7 `${n => { return n; }}${n => { return n; }}${n => { return n; }}`;
|
||||
someGenerics7 `${(n) => { return n; }}${(n) => { return n; }}${(n) => { return n; }}`;
|
||||
// Generic tag with argument of generic function type
|
||||
function someGenerics8(strs, n) {
|
||||
return n;
|
||||
|
||||
@@ -118,5 +118,5 @@ fn4 `${null}${true}`;
|
||||
function fn5() {
|
||||
return undefined;
|
||||
}
|
||||
fn5 `${function (n) { return n.toFixed(); }}`; // will error; 'n' should have type 'string'.
|
||||
fn5 `${function (n) { return n.substr(0); }}`;
|
||||
fn5 `${(n) => { return n.toFixed(); }}`; // will error; 'n' should have type 'string'.
|
||||
fn5 `${(n) => { return n.substr(0); }}`;
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
var x = x => `abc${ x }def`;
|
||||
|
||||
//// [templateStringInArrowFunctionES6.js]
|
||||
var x = function (x) { return `abc${x}def`; };
|
||||
var x = x => { return `abc${x}def`; };
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
var x = `abc${ x => x }def`;
|
||||
|
||||
//// [templateStringWithEmbeddedArrowFunctionES6.js]
|
||||
var x = `abc${function (x) { return x; }}def`;
|
||||
var x = `abc${x => { return x; }}def`;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithObjectLiteral.ts(35,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
|
||||
Type argument candidate 'E1' is not a valid type argument because it is not a supertype of candidate 'E2'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithObjectLiteral.ts (1 errors) ====
|
||||
interface Computed<T> {
|
||||
read(): T;
|
||||
write(value: T);
|
||||
}
|
||||
|
||||
function foo<T>(x: Computed<T>) { }
|
||||
|
||||
var s: string;
|
||||
|
||||
// Calls below should infer string for T and then assign that type to the value parameter
|
||||
foo({
|
||||
read: () => s,
|
||||
write: value => s = value
|
||||
});
|
||||
foo({
|
||||
write: value => s = value,
|
||||
read: () => s
|
||||
});
|
||||
|
||||
enum E1 { X }
|
||||
enum E2 { X }
|
||||
|
||||
// Check that we infer from both a.r and b before fixing T in a.w
|
||||
|
||||
declare function f1<T, U>(a: { w: (x: T) => U; r: () => T; }, b: T): U;
|
||||
|
||||
var v1: number;
|
||||
var v1 = f1({ w: x => x, r: () => 0 }, 0);
|
||||
var v1 = f1({ w: x => x, r: () => 0 }, E1.X);
|
||||
var v1 = f1({ w: x => x, r: () => E1.X }, 0);
|
||||
|
||||
var v2: E1;
|
||||
var v2 = f1({ w: x => x, r: () => E1.X }, E1.X);
|
||||
|
||||
var v3 = f1({ w: x => x, r: () => E1.X }, E2.X); // Error
|
||||
~~
|
||||
!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
|
||||
!!! error TS2453: Type argument candidate 'E1' is not a valid type argument because it is not a supertype of candidate 'E2'.
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
//// [typeArgumentInferenceWithObjectLiteral.ts]
|
||||
interface Computed<T> {
|
||||
read(): T;
|
||||
write(value: T);
|
||||
}
|
||||
|
||||
function foo<T>(x: Computed<T>) { }
|
||||
|
||||
var s: string;
|
||||
|
||||
// Calls below should infer string for T and then assign that type to the value parameter
|
||||
foo({
|
||||
read: () => s,
|
||||
write: value => s = value
|
||||
});
|
||||
foo({
|
||||
write: value => s = value,
|
||||
read: () => s
|
||||
});
|
||||
|
||||
enum E1 { X }
|
||||
enum E2 { X }
|
||||
|
||||
// Check that we infer from both a.r and b before fixing T in a.w
|
||||
|
||||
declare function f1<T, U>(a: { w: (x: T) => U; r: () => T; }, b: T): U;
|
||||
|
||||
var v1: number;
|
||||
var v1 = f1({ w: x => x, r: () => 0 }, 0);
|
||||
var v1 = f1({ w: x => x, r: () => 0 }, E1.X);
|
||||
var v1 = f1({ w: x => x, r: () => E1.X }, 0);
|
||||
|
||||
var v2: E1;
|
||||
var v2 = f1({ w: x => x, r: () => E1.X }, E1.X);
|
||||
|
||||
var v3 = f1({ w: x => x, r: () => E1.X }, E2.X); // Error
|
||||
|
||||
|
||||
//// [typeArgumentInferenceWithObjectLiteral.js]
|
||||
function foo(x) {
|
||||
}
|
||||
var s;
|
||||
// Calls below should infer string for T and then assign that type to the value parameter
|
||||
foo({
|
||||
read: function () { return s; },
|
||||
write: function (value) { return s = value; }
|
||||
});
|
||||
foo({
|
||||
write: function (value) { return s = value; },
|
||||
read: function () { return s; }
|
||||
});
|
||||
var E1;
|
||||
(function (E1) {
|
||||
E1[E1["X"] = 0] = "X";
|
||||
})(E1 || (E1 = {}));
|
||||
var E2;
|
||||
(function (E2) {
|
||||
E2[E2["X"] = 0] = "X";
|
||||
})(E2 || (E2 = {}));
|
||||
var v1;
|
||||
var v1 = f1({ w: function (x) { return x; }, r: function () { return 0; } }, 0);
|
||||
var v1 = f1({ w: function (x) { return x; }, r: function () { return 0; } }, 0 /* X */);
|
||||
var v1 = f1({ w: function (x) { return x; }, r: function () { return 0 /* X */; } }, 0);
|
||||
var v2;
|
||||
var v2 = f1({ w: function (x) { return x; }, r: function () { return 0 /* X */; } }, 0 /* X */);
|
||||
var v3 = f1({ w: function (x) { return x; }, r: function () { return 0 /* X */; } }, 0 /* X */); // Error
|
||||
@@ -0,0 +1,16 @@
|
||||
module m {
|
||||
export class variable{
|
||||
s: string;
|
||||
}
|
||||
export function doSomething(v: m.variable) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class variable {
|
||||
t: number;
|
||||
}
|
||||
|
||||
|
||||
var v: variable = new variable();
|
||||
m.doSomething(v);
|
||||
@@ -0,0 +1,8 @@
|
||||
// @target:es5
|
||||
var f1 = () => { }
|
||||
var f2 = (x: string, y: string) => { }
|
||||
var f3 = (x: string, y: number, ...rest) => { }
|
||||
var f4 = (x: string, y: number, z = 10) => { }
|
||||
function foo(func: () => boolean) { }
|
||||
foo(() => true);
|
||||
foo(() => { return false; });
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target:ES5
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target:ES6
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
@@ -0,0 +1,8 @@
|
||||
// @target:es6
|
||||
var f1 = () => { }
|
||||
var f2 = (x: string, y: string) => { }
|
||||
var f3 = (x: string, y: number, ...rest) => { }
|
||||
var f4 = (x: string, y: number, z=10) => { }
|
||||
function foo(func: () => boolean) { }
|
||||
foo(() => true);
|
||||
foo(() => { return false; });
|
||||
@@ -0,0 +1,14 @@
|
||||
// @target:es5
|
||||
var f1 = () => {
|
||||
this.age = 10
|
||||
};
|
||||
|
||||
var f2 = (x: string) => {
|
||||
this.name = x
|
||||
}
|
||||
|
||||
function foo(func: () => boolean) { }
|
||||
foo(() => {
|
||||
this.age = 100;
|
||||
return true;
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
// @target:es6
|
||||
var f1 = () => {
|
||||
this.age = 10
|
||||
};
|
||||
|
||||
var f2 = (x: string) => {
|
||||
this.name = x
|
||||
}
|
||||
|
||||
function foo(func: () => boolean){ }
|
||||
foo(() => {
|
||||
this.age = 100;
|
||||
return true;
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
// @target: es6
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
}
|
||||
|
||||
function baz() {
|
||||
() => {
|
||||
var arg = arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
function foo(inputFunc: () => void) { }
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
});
|
||||
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
|
||||
|
||||
() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// @target: es6
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
|
||||
var b = function () {
|
||||
var a = () => {
|
||||
var arg = arguments[0]; // error
|
||||
}
|
||||
}
|
||||
|
||||
function baz() {
|
||||
() => {
|
||||
var arg = arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
function foo(inputFunc: () => void) { }
|
||||
foo(() => {
|
||||
var arg = arguments[0]; // error
|
||||
});
|
||||
|
||||
function bar() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
|
||||
|
||||
() => {
|
||||
function foo() {
|
||||
var arg = arguments[0]; // no error
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target:ES5
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target:ES6
|
||||
var arrow1 = a => { };
|
||||
var arrow2 = (a) => { };
|
||||
|
||||
var arrow3 = (a, b) => { };
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
interface Computed<T> {
|
||||
read(): T;
|
||||
write(value: T);
|
||||
}
|
||||
|
||||
function foo<T>(x: Computed<T>) { }
|
||||
|
||||
var s: string;
|
||||
|
||||
// Calls below should infer string for T and then assign that type to the value parameter
|
||||
foo({
|
||||
read: () => s,
|
||||
write: value => s = value
|
||||
});
|
||||
foo({
|
||||
write: value => s = value,
|
||||
read: () => s
|
||||
});
|
||||
|
||||
enum E1 { X }
|
||||
enum E2 { X }
|
||||
|
||||
// Check that we infer from both a.r and b before fixing T in a.w
|
||||
|
||||
declare function f1<T, U>(a: { w: (x: T) => U; r: () => T; }, b: T): U;
|
||||
|
||||
var v1: number;
|
||||
var v1 = f1({ w: x => x, r: () => 0 }, 0);
|
||||
var v1 = f1({ w: x => x, r: () => 0 }, E1.X);
|
||||
var v1 = f1({ w: x => x, r: () => E1.X }, 0);
|
||||
|
||||
var v2: E1;
|
||||
var v2 = f1({ w: x => x, r: () => E1.X }, E1.X);
|
||||
|
||||
var v3 = f1({ w: x => x, r: () => E1.X }, E2.X); // Error
|
||||
Reference in New Issue
Block a user