diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 61cf701eb953b..887a406bb8c35 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -119,6 +119,7 @@ namespace ts { const resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__"); const anyType = createIntrinsicType(TypeFlags.Any, "any"); + const autoType = createIntrinsicType(TypeFlags.Any, "any"); const unknownType = createIntrinsicType(TypeFlags.Any, "unknown"); const undefinedType = createIntrinsicType(TypeFlags.Undefined, "undefined"); const undefinedWideningType = strictNullChecks ? undefinedType : createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsWideningType, "undefined"); @@ -3050,6 +3051,11 @@ namespace ts { return undefined; } + function isAutoVariableInitializer(initializer: Expression) { + const expr = initializer && skipParentheses(initializer); + return !expr || expr.kind === SyntaxKind.NullKeyword || expr.kind === SyntaxKind.Identifier && getResolvedSymbol(expr) === undefinedSymbol; + } + function addOptionality(type: Type, optional: boolean): Type { return strictNullChecks && optional ? includeFalsyTypes(type, TypeFlags.Undefined) : type; } @@ -3088,6 +3094,14 @@ namespace ts { return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality); } + // Use control flow type inference for non-ambient, non-exported var or let variables with no initializer + // or a 'null' or 'undefined' initializer. + if (declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) && + !(getCombinedNodeFlags(declaration) & NodeFlags.Const) && !(getCombinedModifierFlags(declaration) & ModifierFlags.Export) && + !isInAmbientContext(declaration) && isAutoVariableInitializer(declaration.initializer)) { + return autoType; + } + if (declaration.kind === SyntaxKind.Parameter) { const func = declaration.parent; // For a parameter of a set accessor, use the type of the get accessor if one is present @@ -8432,7 +8446,9 @@ namespace ts { if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) { return declaredType; } - const initialType = assumeInitialized ? declaredType : includeFalsyTypes(declaredType, TypeFlags.Undefined); + const initialType = assumeInitialized ? declaredType : + declaredType === autoType ? undefinedType : + includeFalsyTypes(declaredType, TypeFlags.Undefined); const visitedFlowStart = visitedFlowCount; const result = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode)); visitedFlowCount = visitedFlowStart; @@ -8506,9 +8522,12 @@ namespace ts { // Assignments only narrow the computed type if the declared type is a union type. Thus, we // only need to evaluate the assigned type if the declared type is a union type. if (isMatchingReference(reference, node)) { - const isIncrementOrDecrement = node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression; - return declaredType.flags & TypeFlags.Union && !isIncrementOrDecrement ? - getAssignmentReducedType(declaredType, getInitialOrAssignedType(node)) : + if (node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression) { + const flowType = getTypeAtFlowNode(flow.antecedent); + return createFlowType(getBaseTypeOfLiteralType(getTypeFromFlowType(flowType)), isIncomplete(flowType)); + } + return declaredType === autoType ? getBaseTypeOfLiteralType(getInitialOrAssignedType(node)) : + declaredType.flags & TypeFlags.Union ? getAssignmentReducedType(declaredType, getInitialOrAssignedType(node)) : declaredType; } // We didn't have a direct match. However, if the reference is a dotted name, this @@ -8952,7 +8971,7 @@ namespace ts { if (isRightSideOfQualifiedNameOrPropertyAccess(location)) { location = location.parent; } - if (isExpression(location) && !isAssignmentTarget(location)) { + if (isPartOfExpression(location) && !isAssignmentTarget(location)) { const type = checkExpression(location); if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) { return type; @@ -9123,13 +9142,23 @@ namespace ts { // We only look for uninitialized variables in strict null checking mode, and only when we can analyze // the entire control flow graph from the variable's declaration (i.e. when the flow container and // declaration container are the same). - const assumeInitialized = !strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isParameter || - isOuterVariable || isInAmbientContext(declaration); + const assumeInitialized = isParameter || isOuterVariable || + type !== autoType && (!strictNullChecks || (type.flags & TypeFlags.Any) !== 0) || + isInAmbientContext(declaration); const flowType = getFlowTypeOfReference(node, type, assumeInitialized, flowContainer); // A variable is considered uninitialized when it is possible to analyze the entire control flow graph // from declaration to use, and when the variable's declared type doesn't include undefined but the // control flow based type does include undefined. - if (!assumeInitialized && !(getFalsyFlags(type) & TypeFlags.Undefined) && getFalsyFlags(flowType) & TypeFlags.Undefined) { + if (type === autoType) { + if (flowType === autoType) { + if (compilerOptions.noImplicitAny) { + error(declaration.name, Diagnostics.Variable_0_implicitly_has_type_any_in_some_locations_where_its_type_cannot_be_determined, symbolToString(symbol)); + error(node, Diagnostics.Variable_0_implicitly_has_an_1_type, symbolToString(symbol), typeToString(anyType)); + } + return anyType; + } + } + else if (!assumeInitialized && !(getFalsyFlags(type) & TypeFlags.Undefined) && getFalsyFlags(flowType) & TypeFlags.Undefined) { error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol)); // Return the declared type to reduce follow-on errors return type; @@ -15874,6 +15903,10 @@ namespace ts { } } + function convertAutoToAny(type: Type) { + return type === autoType ? anyType : type; + } + // Check variable, parameter, or property declaration function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { checkDecorators(node); @@ -15924,7 +15957,7 @@ namespace ts { return; } const symbol = getSymbolOfNode(node); - const type = getTypeOfVariableOrParameterOrProperty(symbol); + const type = convertAutoToAny(getTypeOfVariableOrParameterOrProperty(symbol)); if (node === symbol.valueDeclaration) { // Node is the primary declaration of the symbol, just validate the initializer // Don't validate for-in initializer as it is already an error @@ -15936,7 +15969,7 @@ namespace ts { else { // Node is a secondary declaration, check that type is identical to primary declaration and check that // initializer is consistent with type associated with the node - const declarationType = getWidenedTypeForVariableLikeDeclaration(node); + const declarationType = convertAutoToAny(getWidenedTypeForVariableLikeDeclaration(node)); if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) { error(node.name, Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, declarationNameToString(node.name), typeToString(type), typeToString(declarationType)); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 11eb12bb2b418..fe196b29216da 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2953,6 +2953,10 @@ "category": "Error", "code": 7033 }, + "Variable '{0}' implicitly has type 'any' in some locations where its type cannot be determined.": { + "category": "Error", + "code": 7034 + }, "You cannot rename this element.": { "category": "Error", "code": 8000 diff --git a/tests/baselines/reference/ES5SymbolProperty2.errors.txt b/tests/baselines/reference/ES5SymbolProperty2.errors.txt index 9a6526a2f86a5..97579a4f27a06 100644 --- a/tests/baselines/reference/ES5SymbolProperty2.errors.txt +++ b/tests/baselines/reference/ES5SymbolProperty2.errors.txt @@ -4,7 +4,7 @@ tests/cases/conformance/Symbols/ES5SymbolProperty2.ts(10,11): error TS2304: Cann ==== tests/cases/conformance/Symbols/ES5SymbolProperty2.ts (2 errors) ==== module M { - var Symbol; + var Symbol: any; export class C { [Symbol.iterator]() { } diff --git a/tests/baselines/reference/ES5SymbolProperty2.js b/tests/baselines/reference/ES5SymbolProperty2.js index f04a4671d3f18..0cfe717ae56ea 100644 --- a/tests/baselines/reference/ES5SymbolProperty2.js +++ b/tests/baselines/reference/ES5SymbolProperty2.js @@ -1,6 +1,6 @@ //// [ES5SymbolProperty2.ts] module M { - var Symbol; + var Symbol: any; export class C { [Symbol.iterator]() { } diff --git a/tests/baselines/reference/ES5SymbolProperty3.errors.txt b/tests/baselines/reference/ES5SymbolProperty3.errors.txt index 7c6cc5a9cd77b..2953ed6ac6ab1 100644 --- a/tests/baselines/reference/ES5SymbolProperty3.errors.txt +++ b/tests/baselines/reference/ES5SymbolProperty3.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/Symbols/ES5SymbolProperty3.ts(4,6): error TS2471: A comp ==== tests/cases/conformance/Symbols/ES5SymbolProperty3.ts (1 errors) ==== - var Symbol; + var Symbol: any; class C { [Symbol.iterator]() { } diff --git a/tests/baselines/reference/ES5SymbolProperty3.js b/tests/baselines/reference/ES5SymbolProperty3.js index 6589858625c4c..084f79bd077f2 100644 --- a/tests/baselines/reference/ES5SymbolProperty3.js +++ b/tests/baselines/reference/ES5SymbolProperty3.js @@ -1,5 +1,5 @@ //// [ES5SymbolProperty3.ts] -var Symbol; +var Symbol: any; class C { [Symbol.iterator]() { } diff --git a/tests/baselines/reference/anyPlusAny1.js b/tests/baselines/reference/anyPlusAny1.js index 457688933d7d6..4b28a1d22e26b 100644 --- a/tests/baselines/reference/anyPlusAny1.js +++ b/tests/baselines/reference/anyPlusAny1.js @@ -1,5 +1,5 @@ //// [anyPlusAny1.ts] -var x; +var x: any; x.name = "hello"; var z = x + x; diff --git a/tests/baselines/reference/anyPlusAny1.symbols b/tests/baselines/reference/anyPlusAny1.symbols index e0552e4541f53..3b33a11987ecc 100644 --- a/tests/baselines/reference/anyPlusAny1.symbols +++ b/tests/baselines/reference/anyPlusAny1.symbols @@ -1,5 +1,5 @@ === tests/cases/compiler/anyPlusAny1.ts === -var x; +var x: any; >x : Symbol(x, Decl(anyPlusAny1.ts, 0, 3)) x.name = "hello"; diff --git a/tests/baselines/reference/anyPlusAny1.types b/tests/baselines/reference/anyPlusAny1.types index f6ca9c4996eee..67323a10fd6be 100644 --- a/tests/baselines/reference/anyPlusAny1.types +++ b/tests/baselines/reference/anyPlusAny1.types @@ -1,5 +1,5 @@ === tests/cases/compiler/anyPlusAny1.ts === -var x; +var x: any; >x : any x.name = "hello"; diff --git a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types index 7492a698e3a26..c2d9213ca6045 100644 --- a/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types +++ b/tests/baselines/reference/asiPreventsParsingAsTypeAlias01.types @@ -10,10 +10,10 @@ var Foo; >Foo : any type ->type : any +>type : undefined Foo = string; ->Foo = string : any +>Foo = string : undefined >Foo : any ->string : any +>string : undefined diff --git a/tests/baselines/reference/assignEveryTypeToAny.types b/tests/baselines/reference/assignEveryTypeToAny.types index cfc24e1da65b8..fd1dccefae059 100644 --- a/tests/baselines/reference/assignEveryTypeToAny.types +++ b/tests/baselines/reference/assignEveryTypeToAny.types @@ -59,9 +59,9 @@ var e = undefined; >undefined : undefined x = e; ->x = e : any +>x = e : undefined >x : any ->e : any +>e : undefined var e2: typeof undefined; >e2 : any diff --git a/tests/baselines/reference/assignmentLHSIsReference.js b/tests/baselines/reference/assignmentLHSIsReference.js index f0af56ebc3b68..85d2aab2c46d3 100644 --- a/tests/baselines/reference/assignmentLHSIsReference.js +++ b/tests/baselines/reference/assignmentLHSIsReference.js @@ -1,5 +1,5 @@ //// [assignmentLHSIsReference.ts] -var value; +var value: any; // identifiers: variable and parameter var x1: number; diff --git a/tests/baselines/reference/assignmentLHSIsReference.symbols b/tests/baselines/reference/assignmentLHSIsReference.symbols index b551557708f8e..417ba3c07ea27 100644 --- a/tests/baselines/reference/assignmentLHSIsReference.symbols +++ b/tests/baselines/reference/assignmentLHSIsReference.symbols @@ -1,5 +1,5 @@ === tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts === -var value; +var value: any; >value : Symbol(value, Decl(assignmentLHSIsReference.ts, 0, 3)) // identifiers: variable and parameter diff --git a/tests/baselines/reference/assignmentLHSIsReference.types b/tests/baselines/reference/assignmentLHSIsReference.types index dfb3b236c0aa2..2a7fa2982aa87 100644 --- a/tests/baselines/reference/assignmentLHSIsReference.types +++ b/tests/baselines/reference/assignmentLHSIsReference.types @@ -1,5 +1,5 @@ === tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts === -var value; +var value: any; >value : any // identifiers: variable and parameter diff --git a/tests/baselines/reference/assignmentLHSIsValue.errors.txt b/tests/baselines/reference/assignmentLHSIsValue.errors.txt index bf253df5e70d0..f97ae2bcfa5c1 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/assignmentLHSIsValue.errors.txt @@ -41,7 +41,7 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7 ==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (39 errors) ==== // expected error for all the LHS of assignments - var value; + var value: any; // this class C { diff --git a/tests/baselines/reference/assignmentLHSIsValue.js b/tests/baselines/reference/assignmentLHSIsValue.js index 8a3b4b35d0b87..8f2014ff211b6 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.js +++ b/tests/baselines/reference/assignmentLHSIsValue.js @@ -1,6 +1,6 @@ //// [assignmentLHSIsValue.ts] // expected error for all the LHS of assignments -var value; +var value: any; // this class C { diff --git a/tests/baselines/reference/capturedLetConstInLoop9.types b/tests/baselines/reference/capturedLetConstInLoop9.types index 486697b8d8409..453176a40c92f 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9.types +++ b/tests/baselines/reference/capturedLetConstInLoop9.types @@ -39,7 +39,7 @@ for (let x = 0; x < 1; ++x) { } switch (x) { ->x : any +>x : undefined case 1: >1 : 1 diff --git a/tests/baselines/reference/capturedLetConstInLoop9_ES6.types b/tests/baselines/reference/capturedLetConstInLoop9_ES6.types index be4457315eeeb..df118279f3022 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop9_ES6.types @@ -40,7 +40,7 @@ for (let x = 0; x < 1; ++x) { } switch (x) { ->x : any +>x : undefined case 1: >1 : 1 diff --git a/tests/baselines/reference/commentsArgumentsOfCallExpression2.types b/tests/baselines/reference/commentsArgumentsOfCallExpression2.types index 7ec29aa912430..bc6bf5baa90ad 100644 --- a/tests/baselines/reference/commentsArgumentsOfCallExpression2.types +++ b/tests/baselines/reference/commentsArgumentsOfCallExpression2.types @@ -17,7 +17,7 @@ foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b); >1 : 1 >2 : 2 >a + b : any ->a : any +>a : undefined >b : any foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b); @@ -26,7 +26,7 @@ foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b); >function () { } : () => void >() => { } : () => void >a + /*e3*/ b : any ->a : any +>a : undefined >b : any foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b)); @@ -36,7 +36,7 @@ foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b)); >() => { } : () => void >(a + b) : any >a + b : any ->a : any +>a : undefined >b : any foo( diff --git a/tests/baselines/reference/compoundAssignmentLHSIsReference.types b/tests/baselines/reference/compoundAssignmentLHSIsReference.types index 4816307f50895..a82eb17426d5a 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsReference.types +++ b/tests/baselines/reference/compoundAssignmentLHSIsReference.types @@ -9,12 +9,12 @@ var x1: number; x1 *= value; >x1 *= value : number >x1 : number ->value : any +>value : undefined x1 += value; ->x1 += value : any +>x1 += value : number >x1 : number ->value : any +>value : undefined function fn1(x2: number) { >fn1 : (x2: number) => void @@ -41,41 +41,41 @@ x3.a *= value; >x3.a : number >x3 : { a: number; } >a : number ->value : any +>value : undefined x3.a += value; ->x3.a += value : any +>x3.a += value : number >x3.a : number >x3 : { a: number; } >a : number ->value : any +>value : undefined x3['a'] *= value; >x3['a'] *= value : number >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : any +>value : undefined x3['a'] += value; ->x3['a'] += value : any +>x3['a'] += value : number >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : any +>value : undefined // parentheses, the contained expression is reference (x1) *= value; >(x1) *= value : number >(x1) : number >x1 : number ->value : any +>value : undefined (x1) += value; ->(x1) += value : any +>(x1) += value : number >(x1) : number >x1 : number ->value : any +>value : undefined function fn2(x4: number) { >fn2 : (x4: number) => void @@ -100,15 +100,15 @@ function fn2(x4: number) { >x3.a : number >x3 : { a: number; } >a : number ->value : any +>value : undefined (x3.a) += value; ->(x3.a) += value : any +>(x3.a) += value : number >(x3.a) : number >x3.a : number >x3 : { a: number; } >a : number ->value : any +>value : undefined (x3['a']) *= value; >(x3['a']) *= value : number @@ -116,13 +116,13 @@ function fn2(x4: number) { >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : any +>value : undefined (x3['a']) += value; ->(x3['a']) += value : any +>(x3['a']) += value : number >(x3['a']) : number >x3['a'] : number >x3 : { a: number; } >'a' : "a" ->value : any +>value : undefined diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt index 392e1781dd5f5..61f893ba88fa5 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt @@ -77,7 +77,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa ==== tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts (74 errors) ==== // expected error for all the LHS of compound assignments (arithmetic and addition) - var value; + var value: any; // this class C { diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.js b/tests/baselines/reference/compoundAssignmentLHSIsValue.js index a55c068d4a422..618daea339e16 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.js +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.js @@ -1,7 +1,7 @@ //// [compoundAssignmentLHSIsValue.ts] // expected error for all the LHS of compound assignments (arithmetic and addition) -var value; +var value: any; // this class C { diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.js b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.js index dfee41fad8143..d5104f1dbdcab 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.js +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.js @@ -1,5 +1,5 @@ //// [compoundExponentiationAssignmentLHSIsReference.ts] -var value; +var value: any; // identifiers: variable and parameter var x1: number; diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.symbols b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.symbols index 775d43b0c58c7..b69c1afdb9b8c 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.symbols +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.symbols @@ -1,5 +1,5 @@ === tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts === -var value; +var value: any; >value : Symbol(value, Decl(compoundExponentiationAssignmentLHSIsReference.ts, 0, 3)) // identifiers: variable and parameter diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.types b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.types index 55b90382d7ba8..32230f7f8efba 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.types +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsReference.types @@ -1,5 +1,5 @@ === tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts === -var value; +var value: any; >value : any // identifiers: variable and parameter diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt index 23720468bb7d5..0d9bab910ef88 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt @@ -40,7 +40,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm ==== tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts (38 errors) ==== // expected error for all the LHS of compound assignments (arithmetic and addition) - var value; + var value: any; // this class C { diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js index 16500b823b8f6..f9e58817eceb0 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.js @@ -1,6 +1,6 @@ //// [compoundExponentiationAssignmentLHSIsValue.ts] // expected error for all the LHS of compound assignments (arithmetic and addition) -var value; +var value: any; // this class C { diff --git a/tests/baselines/reference/constraintSatisfactionWithAny.types b/tests/baselines/reference/constraintSatisfactionWithAny.types index f3363fe1a9006..2f9c755328826 100644 --- a/tests/baselines/reference/constraintSatisfactionWithAny.types +++ b/tests/baselines/reference/constraintSatisfactionWithAny.types @@ -35,20 +35,20 @@ var a; >a : any foo(a); ->foo(a) : any +>foo(a) : undefined >foo : (x: T) => T ->a : any +>a : undefined foo2(a); ->foo2(a) : any +>foo2(a) : undefined >foo2 : (x: T) => T ->a : any +>a : undefined //foo3(a); foo4(a); ->foo4(a) : any +>foo4(a) : undefined >foo4 : (x: T) => void>(x: T) => T ->a : any +>a : undefined var b: number; >b : number @@ -84,10 +84,10 @@ class C { } var c1 = new C(a); ->c1 : C ->new C(a) : C +>c1 : C +>new C(a) : C >C : typeof C ->a : any +>a : undefined var c2 = new C(b); >c2 : C @@ -106,10 +106,10 @@ class C2 { } var c3 = new C2(a); ->c3 : C2 ->new C2(a) : C2 +>c3 : C2 +>new C2(a) : C2 >C2 : typeof C2 ->a : any +>a : undefined var c4 = new C2(b); >c4 : C2 @@ -138,10 +138,10 @@ class C4(x:T) => T> { } var c7 = new C4(a); ->c7 : C4 ->new C4(a) : C4 +>c7 : C4 +>new C4(a) : C4 >C4 : typeof C4 ->a : any +>a : undefined var c8 = new C4(b); >c8 : C4 diff --git a/tests/baselines/reference/controlFlowCaching.errors.txt b/tests/baselines/reference/controlFlowCaching.errors.txt new file mode 100644 index 0000000000000..1086695313e84 --- /dev/null +++ b/tests/baselines/reference/controlFlowCaching.errors.txt @@ -0,0 +1,128 @@ +tests/cases/compiler/controlFlowCaching.ts(38,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(38,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(40,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(40,29): error TS2339: Property 'x' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(42,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(42,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(44,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(44,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(46,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(46,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(48,17): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(48,29): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(53,5): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(53,14): error TS2339: Property 'y' does not exist on type 'never'. +tests/cases/compiler/controlFlowCaching.ts(55,14): error TS2678: Type '"start"' is not comparable to type 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(58,14): error TS2678: Type '"end"' is not comparable to type 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(61,14): error TS2678: Type '"middle"' is not comparable to type 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(62,13): error TS2532: Object is possibly 'undefined'. +tests/cases/compiler/controlFlowCaching.ts(62,25): error TS2339: Property 'y' does not exist on type 'never'. + + +==== tests/cases/compiler/controlFlowCaching.ts (19 errors) ==== + + // Repro for #8401 + + function f(dim, offsets, arr, acommon, centerAnchorLimit, g, has, lin) { + var isRtl = this._isRtl(); // chart mirroring + // prepare variable + var o = this.opt, ta = this.chart.theme.axis, position = o.position, + leftBottom = position !== "rightOrTop", rotation = o.rotation % 360, + start, stop, titlePos, titleRotation = 0, titleOffset, axisVector, tickVector, anchorOffset, labelOffset, labelAlign, + labelGap = this.chart.theme.axis.tick.labelGap, + taFont = o.font || (ta.majorTick && ta.majorTick.font) || (ta.tick && ta.tick.font), + taTitleFont = o.titleFont || (ta.title && ta.title.font), + taFontColor = o.fontColor || (ta.majorTick && ta.majorTick.fontColor) || (ta.tick && ta.tick.fontColor) || "black", + taTitleFontColor = o.titleFontColor || (ta.title && ta.title.fontColor) || "black", + taTitleGap = (o.titleGap == 0) ? 0 : o.titleGap || (ta.title && ta.title.gap) || 15, + taTitleOrientation = o.titleOrientation || (ta.title && ta.title.orientation) || "axis", + taMajorTick = this.chart.theme.getTick("major", o), + taMinorTick = this.chart.theme.getTick("minor", o), + taMicroTick = this.chart.theme.getTick("micro", o), + + taStroke = "stroke" in o ? o.stroke : ta.stroke, + size = taFont ? g.normalizedLength(g.splitFontString(taFont).size) : 0, + cosr = Math.abs(Math.cos(rotation * Math.PI / 180)), + sinr = Math.abs(Math.sin(rotation * Math.PI / 180)), + tsize = taTitleFont ? g.normalizedLength(g.splitFontString(taTitleFont).size) : 0; + if (rotation < 0) { + rotation += 360; + } + var cachedLabelW = this._getMaxLabelSize(); + cachedLabelW = cachedLabelW && cachedLabelW.majLabelW; + titleOffset = size * cosr + (cachedLabelW || 0) * sinr + labelGap + Math.max(taMajorTick.length > 0 ? taMajorTick.length : 0, + taMinorTick.length > 0 ? taMinorTick.length : 0) + + tsize + taTitleGap; + axisVector = { x: isRtl ? -1 : 1, y: 0 }; // chart mirroring + switch (rotation) { + default: + if (rotation < (90 - centerAnchorLimit)) { + labelOffset.y = leftBottom ? size : 0; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } else if (rotation < (90 + centerAnchorLimit)) { + labelOffset.x = -size * 0.4; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'x' does not exist on type 'never'. + } else if (rotation < 180) { + labelOffset.y = leftBottom ? 0 : -size; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } else if (rotation < (270 - centerAnchorLimit)) { + labelOffset.y = leftBottom ? 0 : -size; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } else if (rotation < (270 + centerAnchorLimit)) { + labelOffset.y = leftBottom ? size * 0.4 : 0; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } else { + labelOffset.y = leftBottom ? size : 0; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + } + } + + titleRotation = (taTitleOrientation && taTitleOrientation == "away") ? 180 : 0; + titlePos.y = offsets.t - titleOffset + (titleRotation ? 0 : tsize); + ~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + switch (labelAlign) { + case "start": + ~~~~~~~ +!!! error TS2678: Type '"start"' is not comparable to type 'undefined'. + labelAlign = "end"; + break; + case "end": + ~~~~~ +!!! error TS2678: Type '"end"' is not comparable to type 'undefined'. + labelAlign = "start"; + break; + case "middle": + ~~~~~~~~ +!!! error TS2678: Type '"middle"' is not comparable to type 'undefined'. + labelOffset.y -= size; + ~~~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + ~ +!!! error TS2339: Property 'y' does not exist on type 'never'. + break; + } + + let _ = rotation; + } + \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowIIFE.types b/tests/baselines/reference/controlFlowIIFE.types index 6173e79dbbbd7..7cf4337b53bd0 100644 --- a/tests/baselines/reference/controlFlowIIFE.types +++ b/tests/baselines/reference/controlFlowIIFE.types @@ -118,7 +118,7 @@ maybeNumber++; if (maybeNumber !== undefined) { >maybeNumber !== undefined : boolean ->maybeNumber : number | undefined +>maybeNumber : number >undefined : undefined maybeNumber++; diff --git a/tests/baselines/reference/controlFlowLetVar.js b/tests/baselines/reference/controlFlowLetVar.js new file mode 100644 index 0000000000000..24ad95259b126 --- /dev/null +++ b/tests/baselines/reference/controlFlowLetVar.js @@ -0,0 +1,247 @@ +//// [controlFlowLetVar.ts] + +declare let cond: boolean; + +// CFA for 'let' with no type annotation and initializer +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'let' with with type annotation +function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// CFA for 'var' with no type annotation and initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'var' with with type annotation +function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// No CFA for captured outer variables +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + function f() { + const z = x; // any + } +} + +// No CFA for captured outer variables +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + const f = () => { + const z = x; // any + }; +} + +//// [controlFlowLetVar.js] +// CFA for 'let' with no type annotation and initializer +function f1() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | null +} +// No CFA for 'let' with with type annotation +function f4() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // any +} +// CFA for 'var' with no type annotation and initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | null +} +// No CFA for 'var' with with type annotation +function f8() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // any +} +// No CFA for captured outer variables +function f9() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined + function f() { + var z = x; // any + } +} +// No CFA for captured outer variables +function f10() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined + var f = function () { + var z = x; // any + }; +} diff --git a/tests/baselines/reference/controlFlowLetVar.symbols b/tests/baselines/reference/controlFlowLetVar.symbols new file mode 100644 index 0000000000000..f58edd781b780 --- /dev/null +++ b/tests/baselines/reference/controlFlowLetVar.symbols @@ -0,0 +1,263 @@ +=== tests/cases/compiler/controlFlowLetVar.ts === + +declare let cond: boolean; +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + +// CFA for 'let' with no type annotation and initializer +function f1() { +>f1 : Symbol(f1, Decl(controlFlowLetVar.ts, 1, 26)) + + let x; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowLetVar.ts, 12, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7)) +} + +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { +>f2 : Symbol(f2, Decl(controlFlowLetVar.ts, 13, 1)) + + let x = undefined; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7)) +>undefined : Symbol(undefined) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowLetVar.ts, 24, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7)) +} + +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { +>f3 : Symbol(f3, Decl(controlFlowLetVar.ts, 25, 1)) + + let x = null; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7)) + } + const y = x; // string | number | null +>y : Symbol(y, Decl(controlFlowLetVar.ts, 36, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7)) +} + +// No CFA for 'let' with with type annotation +function f4() { +>f4 : Symbol(f4, Decl(controlFlowLetVar.ts, 37, 1)) + + let x: any; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7)) + } + const y = x; // any +>y : Symbol(y, Decl(controlFlowLetVar.ts, 48, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7)) +} + +// CFA for 'var' with no type annotation and initializer +function f5() { +>f5 : Symbol(f5, Decl(controlFlowLetVar.ts, 49, 1)) + + var x; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowLetVar.ts, 60, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7)) +} + +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { +>f6 : Symbol(f6, Decl(controlFlowLetVar.ts, 61, 1)) + + var x = undefined; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7)) +>undefined : Symbol(undefined) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowLetVar.ts, 72, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7)) +} + +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { +>f7 : Symbol(f7, Decl(controlFlowLetVar.ts, 73, 1)) + + var x = null; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7)) + } + const y = x; // string | number | null +>y : Symbol(y, Decl(controlFlowLetVar.ts, 84, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7)) +} + +// No CFA for 'var' with with type annotation +function f8() { +>f8 : Symbol(f8, Decl(controlFlowLetVar.ts, 85, 1)) + + var x: any; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7)) + } + const y = x; // any +>y : Symbol(y, Decl(controlFlowLetVar.ts, 96, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7)) +} + +// No CFA for captured outer variables +function f9() { +>f9 : Symbol(f9, Decl(controlFlowLetVar.ts, 97, 1)) + + let x; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowLetVar.ts, 108, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) + + function f() { +>f : Symbol(f, Decl(controlFlowLetVar.ts, 108, 16)) + + const z = x; // any +>z : Symbol(z, Decl(controlFlowLetVar.ts, 110, 13)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7)) + } +} + +// No CFA for captured outer variables +function f10() { +>f10 : Symbol(f10, Decl(controlFlowLetVar.ts, 112, 1)) + + let x; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) + } + const y = x; // string | number | undefined +>y : Symbol(y, Decl(controlFlowLetVar.ts, 123, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) + + const f = () => { +>f : Symbol(f, Decl(controlFlowLetVar.ts, 124, 9)) + + const z = x; // any +>z : Symbol(z, Decl(controlFlowLetVar.ts, 125, 13)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7)) + + }; +} diff --git a/tests/baselines/reference/controlFlowLetVar.types b/tests/baselines/reference/controlFlowLetVar.types new file mode 100644 index 0000000000000..09f0ea8348887 --- /dev/null +++ b/tests/baselines/reference/controlFlowLetVar.types @@ -0,0 +1,306 @@ +=== tests/cases/compiler/controlFlowLetVar.ts === + +declare let cond: boolean; +>cond : boolean + +// CFA for 'let' with no type annotation and initializer +function f1() { +>f1 : () => void + + let x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number | undefined +>x : string | number | undefined +} + +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { +>f2 : () => void + + let x = undefined; +>x : any +>undefined : undefined + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number | undefined +>x : string | number | undefined +} + +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { +>f3 : () => void + + let x = null; +>x : any +>null : null + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | null +>y : string | number | null +>x : string | number | null +} + +// No CFA for 'let' with with type annotation +function f4() { +>f4 : () => void + + let x: any; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // any +>y : any +>x : any +} + +// CFA for 'var' with no type annotation and initializer +function f5() { +>f5 : () => void + + var x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number | undefined +>x : string | number | undefined +} + +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { +>f6 : () => void + + var x = undefined; +>x : any +>undefined : undefined + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number | undefined +>x : string | number | undefined +} + +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { +>f7 : () => void + + var x = null; +>x : any +>null : null + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | null +>y : string | number | null +>x : string | number | null +} + +// No CFA for 'var' with with type annotation +function f8() { +>f8 : () => void + + var x: any; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // any +>y : any +>x : any +} + +// No CFA for captured outer variables +function f9() { +>f9 : () => void + + let x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number | undefined +>x : string | number | undefined + + function f() { +>f : () => void + + const z = x; // any +>z : any +>x : any + } +} + +// No CFA for captured outer variables +function f10() { +>f10 : () => void + + let x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; // string | number | undefined +>y : string | number | undefined +>x : string | number | undefined + + const f = () => { +>f : () => void +>() => { const z = x; // any } : () => void + + const z = x; // any +>z : any +>x : any + + }; +} diff --git a/tests/baselines/reference/controlFlowNoImplicitAny.errors.txt b/tests/baselines/reference/controlFlowNoImplicitAny.errors.txt new file mode 100644 index 0000000000000..d081f29d51112 --- /dev/null +++ b/tests/baselines/reference/controlFlowNoImplicitAny.errors.txt @@ -0,0 +1,143 @@ +tests/cases/compiler/controlFlowNoImplicitAny.ts(102,9): error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined. +tests/cases/compiler/controlFlowNoImplicitAny.ts(111,19): error TS7005: Variable 'x' implicitly has an 'any' type. +tests/cases/compiler/controlFlowNoImplicitAny.ts(117,9): error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined. +tests/cases/compiler/controlFlowNoImplicitAny.ts(126,19): error TS7005: Variable 'x' implicitly has an 'any' type. + + +==== tests/cases/compiler/controlFlowNoImplicitAny.ts (4 errors) ==== + + declare let cond: boolean; + + // CFA for 'let' with no type annotation and initializer + function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + } + + // CFA for 'let' with no type annotation and 'undefined' initializer + function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + } + + // CFA for 'let' with no type annotation and 'null' initializer + function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null + } + + // No CFA for 'let' with with type annotation + function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any + } + + // CFA for 'var' with no type annotation and initializer + function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + } + + // CFA for 'var' with no type annotation and 'undefined' initializer + function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + } + + // CFA for 'var' with no type annotation and 'null' initializer + function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null + } + + // No CFA for 'var' with with type annotation + function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any + } + + // No CFA for captured outer variables + function f9() { + let x; + ~ +!!! error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined. + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + function f() { + const z = x; // any + ~ +!!! error TS7005: Variable 'x' implicitly has an 'any' type. + } + } + + // No CFA for captured outer variables + function f10() { + let x; + ~ +!!! error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined. + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + const f = () => { + const z = x; // any + ~ +!!! error TS7005: Variable 'x' implicitly has an 'any' type. + }; + } \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowNoImplicitAny.js b/tests/baselines/reference/controlFlowNoImplicitAny.js new file mode 100644 index 0000000000000..9a5f302d87a39 --- /dev/null +++ b/tests/baselines/reference/controlFlowNoImplicitAny.js @@ -0,0 +1,247 @@ +//// [controlFlowNoImplicitAny.ts] + +declare let cond: boolean; + +// CFA for 'let' with no type annotation and initializer +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'let' with with type annotation +function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// CFA for 'var' with no type annotation and initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'var' with with type annotation +function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// No CFA for captured outer variables +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + function f() { + const z = x; // any + } +} + +// No CFA for captured outer variables +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + const f = () => { + const z = x; // any + }; +} + +//// [controlFlowNoImplicitAny.js] +// CFA for 'let' with no type annotation and initializer +function f1() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | null +} +// No CFA for 'let' with with type annotation +function f4() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // any +} +// CFA for 'var' with no type annotation and initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined +} +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | null +} +// No CFA for 'var' with with type annotation +function f8() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // any +} +// No CFA for captured outer variables +function f9() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined + function f() { + var z = x; // any + } +} +// No CFA for captured outer variables +function f10() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; // string | number | undefined + var f = function () { + var z = x; // any + }; +} diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherType.js b/tests/baselines/reference/decrementOperatorWithAnyOtherType.js index 51015cf44edd3..f3ff58b80ca8a 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherType.js +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherType.js @@ -2,7 +2,7 @@ // -- operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj = {x:1,y:null}; class A { diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherType.symbols b/tests/baselines/reference/decrementOperatorWithAnyOtherType.symbols index cbef74425784d..8d1b023c97aa8 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherType.symbols +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherType.symbols @@ -4,7 +4,7 @@ var ANY: any; >ANY : Symbol(ANY, Decl(decrementOperatorWithAnyOtherType.ts, 2, 3)) -var ANY1; +var ANY1: any; >ANY1 : Symbol(ANY1, Decl(decrementOperatorWithAnyOtherType.ts, 3, 3)) var ANY2: any[] = ["", ""]; diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherType.types b/tests/baselines/reference/decrementOperatorWithAnyOtherType.types index c8b8852e4d27d..74fbd0012d127 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherType.types +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherType.types @@ -4,7 +4,7 @@ var ANY: any; >ANY : any -var ANY1; +var ANY1: any; >ANY1 : any var ANY2: any[] = ["", ""]; diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt index 46e5515633a09..2e1d594164d91 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt @@ -52,7 +52,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp ==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts (50 errors) ==== // -- operator on any type - var ANY1; + var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} @@ -63,7 +63,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.js b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.js index 94f5c942bfc49..88d045ab378d2 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.js +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherTypeInvalidOperations.js @@ -1,6 +1,6 @@ //// [decrementOperatorWithAnyOtherTypeInvalidOperations.ts] // -- operator on any type -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} @@ -11,7 +11,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/downlevelLetConst14.types b/tests/baselines/reference/downlevelLetConst14.types index 29c87e76cce5c..493c17b97cd01 100644 --- a/tests/baselines/reference/downlevelLetConst14.types +++ b/tests/baselines/reference/downlevelLetConst14.types @@ -77,22 +77,22 @@ use(x); use(z0); >use(z0) : any >use : (a: any) => any ->z0 : any +>z0 : undefined use(z1); >use(z1) : any >use : (a: any) => any ->z1 : any +>z1 : undefined use(z2); >use(z2) : any >use : (a: any) => any ->z2 : any +>z2 : undefined use(z3); >use(z3) : any >use : (a: any) => any ->z3 : any +>z3 : undefined var z6; >z6 : any @@ -149,7 +149,7 @@ use(y); use(z6); >use(z6) : any >use : (a: any) => any ->z6 : any +>z6 : undefined var z = false; >z : boolean diff --git a/tests/baselines/reference/downlevelLetConst15.types b/tests/baselines/reference/downlevelLetConst15.types index 9e58c6488214a..6d224b6310d66 100644 --- a/tests/baselines/reference/downlevelLetConst15.types +++ b/tests/baselines/reference/downlevelLetConst15.types @@ -83,22 +83,22 @@ use(x); use(z0); >use(z0) : any >use : (a: any) => any ->z0 : any +>z0 : undefined use(z1); >use(z1) : any >use : (a: any) => any ->z1 : any +>z1 : undefined use(z2); >use(z2) : any >use : (a: any) => any ->z2 : any +>z2 : undefined use(z3); >use(z3) : any >use : (a: any) => any ->z3 : any +>z3 : undefined var z6; >z6 : any @@ -155,7 +155,7 @@ use(y); use(z6); >use(z6) : any >use : (a: any) => any ->z6 : any +>z6 : undefined var z = false; >z : boolean diff --git a/tests/baselines/reference/es5-asyncFunctionTryStatements.js b/tests/baselines/reference/es5-asyncFunctionTryStatements.js index c9c5507afa7d9..513420dd6f452 100644 --- a/tests/baselines/reference/es5-asyncFunctionTryStatements.js +++ b/tests/baselines/reference/es5-asyncFunctionTryStatements.js @@ -1,8 +1,8 @@ //// [es5-asyncFunctionTryStatements.ts] -declare var x, y, z, a, b, c; +declare var x: any, y: any, z: any, a: any, b: any, c: any; async function tryCatch0() { - var x, y; + var x: any, y: any; try { x; } @@ -12,7 +12,7 @@ async function tryCatch0() { } async function tryCatch1() { - var x, y; + var x: any, y: any; try { await x; } @@ -22,7 +22,7 @@ async function tryCatch1() { } async function tryCatch2() { - var x, y; + var x: any, y: any; try { x; } @@ -32,7 +32,7 @@ async function tryCatch2() { } async function tryCatch3(): Promise { - var x, y; + var x: any, y: any; try { await x; } @@ -41,7 +41,7 @@ async function tryCatch3(): Promise { } } async function tryFinally0() { - var x, y; + var x: any, y: any; try { x; } @@ -51,7 +51,7 @@ async function tryFinally0() { } async function tryFinally1() { - var x, y; + var x: any, y: any; try { await x; } @@ -61,7 +61,7 @@ async function tryFinally1() { } async function tryFinally2() { - var x, y; + var x: any, y: any; try { x; } @@ -71,7 +71,7 @@ async function tryFinally2() { } async function tryCatchFinally0() { - var x, y, z; + var x: any, y: any, z: any; try { x; } @@ -84,7 +84,7 @@ async function tryCatchFinally0() { } async function tryCatchFinally1() { - var x, y, z; + var x: any, y: any, z: any; try { await x; } @@ -97,7 +97,7 @@ async function tryCatchFinally1() { } async function tryCatchFinally2() { - var x, y, z; + var x: any, y: any, z: any; try { x; } @@ -110,7 +110,7 @@ async function tryCatchFinally2() { } async function tryCatchFinally3() { - var x, y, z; + var x: any, y: any, z: any; try { x; } diff --git a/tests/baselines/reference/es5-asyncFunctionTryStatements.symbols b/tests/baselines/reference/es5-asyncFunctionTryStatements.symbols index ecf8fbc505b91..52a4ec8df769b 100644 --- a/tests/baselines/reference/es5-asyncFunctionTryStatements.symbols +++ b/tests/baselines/reference/es5-asyncFunctionTryStatements.symbols @@ -1,18 +1,18 @@ === tests/cases/compiler/es5-asyncFunctionTryStatements.ts === -declare var x, y, z, a, b, c; +declare var x: any, y: any, z: any, a: any, b: any, c: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 0, 11)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 0, 14)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 0, 17)) ->a : Symbol(a, Decl(es5-asyncFunctionTryStatements.ts, 0, 20)) ->b : Symbol(b, Decl(es5-asyncFunctionTryStatements.ts, 0, 23)) ->c : Symbol(c, Decl(es5-asyncFunctionTryStatements.ts, 0, 26)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 0, 19)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 0, 27)) +>a : Symbol(a, Decl(es5-asyncFunctionTryStatements.ts, 0, 35)) +>b : Symbol(b, Decl(es5-asyncFunctionTryStatements.ts, 0, 43)) +>c : Symbol(c, Decl(es5-asyncFunctionTryStatements.ts, 0, 51)) async function tryCatch0() { ->tryCatch0 : Symbol(tryCatch0, Decl(es5-asyncFunctionTryStatements.ts, 0, 29)) +>tryCatch0 : Symbol(tryCatch0, Decl(es5-asyncFunctionTryStatements.ts, 0, 59)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 3, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 15)) try { x; @@ -22,16 +22,16 @@ async function tryCatch0() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 7, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 15)) } } async function tryCatch1() { >tryCatch1 : Symbol(tryCatch1, Decl(es5-asyncFunctionTryStatements.ts, 10, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 13, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 15)) try { await x; @@ -41,16 +41,16 @@ async function tryCatch1() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 17, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 15)) } } async function tryCatch2() { >tryCatch2 : Symbol(tryCatch2, Decl(es5-asyncFunctionTryStatements.ts, 20, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 23, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 15)) try { x; @@ -60,7 +60,7 @@ async function tryCatch2() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 27, 11)) await y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 15)) } } @@ -69,9 +69,9 @@ async function tryCatch3(): Promise { >Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 33, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 33, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 33, 15)) try { await x; @@ -87,9 +87,9 @@ async function tryCatch3(): Promise { async function tryFinally0() { >tryFinally0 : Symbol(tryFinally0, Decl(es5-asyncFunctionTryStatements.ts, 40, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 42, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 15)) try { x; @@ -97,16 +97,16 @@ async function tryFinally0() { } finally { y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 15)) } } async function tryFinally1() { >tryFinally1 : Symbol(tryFinally1, Decl(es5-asyncFunctionTryStatements.ts, 49, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 52, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 15)) try { await x; @@ -114,16 +114,16 @@ async function tryFinally1() { } finally { y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 15)) } } async function tryFinally2() { >tryFinally2 : Symbol(tryFinally2, Decl(es5-asyncFunctionTryStatements.ts, 59, 1)) - var x, y; + var x: any, y: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 62, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 15)) try { x; @@ -131,17 +131,17 @@ async function tryFinally2() { } finally { await y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 15)) } } async function tryCatchFinally0() { >tryCatchFinally0 : Symbol(tryCatchFinally0, Decl(es5-asyncFunctionTryStatements.ts, 69, 1)) - var x, y, z; + var x: any, y: any, z: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 72, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 10)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 13)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 15)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 23)) try { x; @@ -151,21 +151,21 @@ async function tryCatchFinally0() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 76, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 15)) } finally { z; ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 13)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 23)) } } async function tryCatchFinally1() { >tryCatchFinally1 : Symbol(tryCatchFinally1, Decl(es5-asyncFunctionTryStatements.ts, 82, 1)) - var x, y, z; + var x: any, y: any, z: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 85, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 10)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 13)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 15)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 23)) try { await x; @@ -175,21 +175,21 @@ async function tryCatchFinally1() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 89, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 15)) } finally { z; ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 13)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 23)) } } async function tryCatchFinally2() { >tryCatchFinally2 : Symbol(tryCatchFinally2, Decl(es5-asyncFunctionTryStatements.ts, 95, 1)) - var x, y, z; + var x: any, y: any, z: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 98, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 10)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 13)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 15)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 23)) try { x; @@ -199,21 +199,21 @@ async function tryCatchFinally2() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 102, 11)) await y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 15)) } finally { z; ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 13)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 23)) } } async function tryCatchFinally3() { >tryCatchFinally3 : Symbol(tryCatchFinally3, Decl(es5-asyncFunctionTryStatements.ts, 108, 1)) - var x, y, z; + var x: any, y: any, z: any; >x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 111, 7)) ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 10)) ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 13)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 15)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 23)) try { x; @@ -223,10 +223,10 @@ async function tryCatchFinally3() { >e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 115, 11)) y; ->y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 10)) +>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 15)) } finally { await z; ->z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 13)) +>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 23)) } } diff --git a/tests/baselines/reference/es5-asyncFunctionTryStatements.types b/tests/baselines/reference/es5-asyncFunctionTryStatements.types index ab1cd84561624..f4c4536c6fc3f 100644 --- a/tests/baselines/reference/es5-asyncFunctionTryStatements.types +++ b/tests/baselines/reference/es5-asyncFunctionTryStatements.types @@ -1,5 +1,5 @@ === tests/cases/compiler/es5-asyncFunctionTryStatements.ts === -declare var x, y, z, a, b, c; +declare var x: any, y: any, z: any, a: any, b: any, c: any; >x : any >y : any >z : any @@ -10,7 +10,7 @@ declare var x, y, z, a, b, c; async function tryCatch0() { >tryCatch0 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -29,7 +29,7 @@ async function tryCatch0() { async function tryCatch1() { >tryCatch1 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -49,7 +49,7 @@ async function tryCatch1() { async function tryCatch2() { >tryCatch2 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -71,7 +71,7 @@ async function tryCatch3(): Promise { >Promise : Promise >Function : Function - var x, y; + var x: any, y: any; >x : any >y : any @@ -91,7 +91,7 @@ async function tryCatch3(): Promise { async function tryFinally0() { >tryFinally0 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -108,7 +108,7 @@ async function tryFinally0() { async function tryFinally1() { >tryFinally1 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -126,7 +126,7 @@ async function tryFinally1() { async function tryFinally2() { >tryFinally2 : () => Promise - var x, y; + var x: any, y: any; >x : any >y : any @@ -144,7 +144,7 @@ async function tryFinally2() { async function tryCatchFinally0() { >tryCatchFinally0 : () => Promise - var x, y, z; + var x: any, y: any, z: any; >x : any >y : any >z : any @@ -168,7 +168,7 @@ async function tryCatchFinally0() { async function tryCatchFinally1() { >tryCatchFinally1 : () => Promise - var x, y, z; + var x: any, y: any, z: any; >x : any >y : any >z : any @@ -193,7 +193,7 @@ async function tryCatchFinally1() { async function tryCatchFinally2() { >tryCatchFinally2 : () => Promise - var x, y, z; + var x: any, y: any, z: any; >x : any >y : any >z : any @@ -218,7 +218,7 @@ async function tryCatchFinally2() { async function tryCatchFinally3() { >tryCatchFinally3 : () => Promise - var x, y, z; + var x: any, y: any, z: any; >x : any >y : any >z : any diff --git a/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt b/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt index af17a7ddf7a32..134a883540efd 100644 --- a/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt +++ b/tests/baselines/reference/exponentiationOperatorSyntaxError2.errors.txt @@ -84,7 +84,7 @@ tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxE ==== tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts (81 errors) ==== // Error: early syntax error using ES7 SimpleUnaryExpression on left-hand side without () - var temp; + var temp: any; delete --temp ** 3; ~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/exponentiationOperatorSyntaxError2.js b/tests/baselines/reference/exponentiationOperatorSyntaxError2.js index 9e07273522fda..e443b756575f6 100644 --- a/tests/baselines/reference/exponentiationOperatorSyntaxError2.js +++ b/tests/baselines/reference/exponentiationOperatorSyntaxError2.js @@ -1,7 +1,7 @@ //// [exponentiationOperatorSyntaxError2.ts] // Error: early syntax error using ES7 SimpleUnaryExpression on left-hand side without () -var temp; +var temp: any; delete --temp ** 3; delete ++temp ** 3; diff --git a/tests/baselines/reference/expr.errors.txt b/tests/baselines/reference/expr.errors.txt index 17e39cc80be2f..23215cac6bae2 100644 --- a/tests/baselines/reference/expr.errors.txt +++ b/tests/baselines/reference/expr.errors.txt @@ -78,7 +78,7 @@ tests/cases/compiler/expr.ts(242,7): error TS2363: The right-hand side of an ari } function f() { - var a; + var a: any; var n=3; var s=""; var b=false; diff --git a/tests/baselines/reference/expr.js b/tests/baselines/reference/expr.js index 9baf55084c12d..689ff1e27dc14 100644 --- a/tests/baselines/reference/expr.js +++ b/tests/baselines/reference/expr.js @@ -7,7 +7,7 @@ enum E { } function f() { - var a; + var a: any; var n=3; var s=""; var b=false; diff --git a/tests/baselines/reference/for-inStatements.errors.txt b/tests/baselines/reference/for-inStatements.errors.txt index 7e20b8ca316ff..f0e6c950ebb0f 100644 --- a/tests/baselines/reference/for-inStatements.errors.txt +++ b/tests/baselines/reference/for-inStatements.errors.txt @@ -18,7 +18,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(79,15): for (var x in /[a-z]/) { } for (var x in new Date()) { } - var c, d, e; + var c: any, d: any, e: any; for (var x in c || d) { } for (var x in e ? c : d) { } diff --git a/tests/baselines/reference/for-inStatements.js b/tests/baselines/reference/for-inStatements.js index 5c097a68ccc3b..7aabf4147589a 100644 --- a/tests/baselines/reference/for-inStatements.js +++ b/tests/baselines/reference/for-inStatements.js @@ -15,7 +15,7 @@ for (var x in fn()) { } for (var x in /[a-z]/) { } for (var x in new Date()) { } -var c, d, e; +var c: any, d: any, e: any; for (var x in c || d) { } for (var x in e ? c : d) { } diff --git a/tests/baselines/reference/for-of3.errors.txt b/tests/baselines/reference/for-of3.errors.txt index ba8e3e4a5c688..99ed3098a6389 100644 --- a/tests/baselines/reference/for-of3.errors.txt +++ b/tests/baselines/reference/for-of3.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/es6/for-ofStatements/for-of3.ts(2,6): error TS2487: Inva ==== tests/cases/conformance/es6/for-ofStatements/for-of3.ts (1 errors) ==== - var v; + var v: any; for (v++ of []) { } ~~~ !!! error TS2487: Invalid left-hand side in 'for...of' statement. \ No newline at end of file diff --git a/tests/baselines/reference/for-of3.js b/tests/baselines/reference/for-of3.js index 7ef271877021a..15918223e6b73 100644 --- a/tests/baselines/reference/for-of3.js +++ b/tests/baselines/reference/for-of3.js @@ -1,5 +1,5 @@ //// [for-of3.ts] -var v; +var v: any; for (v++ of []) { } //// [for-of3.js] diff --git a/tests/baselines/reference/forIn.errors.txt b/tests/baselines/reference/forIn.errors.txt index ccc1423f1aa65..a7dd629698a02 100644 --- a/tests/baselines/reference/forIn.errors.txt +++ b/tests/baselines/reference/forIn.errors.txt @@ -1,17 +1,24 @@ tests/cases/compiler/forIn.ts(2,10): error TS2404: The left-hand side of a 'for...in' statement cannot use a type annotation. +tests/cases/compiler/forIn.ts(2,22): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. +tests/cases/compiler/forIn.ts(7,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. +tests/cases/compiler/forIn.ts(18,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. tests/cases/compiler/forIn.ts(20,4): error TS2304: Cannot find name 'k'. -==== tests/cases/compiler/forIn.ts (2 errors) ==== +==== tests/cases/compiler/forIn.ts (5 errors) ==== var arr = null; for (var i:number in arr) { // error ~ !!! error TS2404: The left-hand side of a 'for...in' statement cannot use a type annotation. + ~~~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. var x1 = arr[i]; var y1 = arr[i]; } for (var j in arr) { // ok + ~~~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. var x2 = arr[j]; var y2 = arr[j]; } @@ -23,6 +30,8 @@ tests/cases/compiler/forIn.ts(20,4): error TS2304: Cannot find name 'k'. } for (var l in arr) { + ~~~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. // error in the body k[l] = 1; ~ diff --git a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.errors.txt b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.errors.txt index 3acb6e47e10aa..36993750ccfdd 100644 --- a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.errors.txt +++ b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.errors.txt @@ -1,19 +1,23 @@ -tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(2,5): error TS7005: Variable 'x' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(3,13): error TS7005: Variable 'foo' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(4,15): error TS7006: Parameter 'k' implicitly has an 'any' type. +tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(3,5): error TS7034: Variable 'y' implicitly has type 'any' in some locations where its type cannot be determined. +tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(4,13): error TS7005: Variable 'foo' implicitly has an 'any' type. +tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(5,15): error TS7006: Parameter 'k' implicitly has an 'any' type. +tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(5,20): error TS7005: Variable 'y' implicitly has an 'any' type. -==== tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts (3 errors) ==== +==== tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts (4 errors) ==== // this should be an error - var x; // error at "x" + var x; // no error, control flow typed + var y; // error because captured ~ -!!! error TS7005: Variable 'x' implicitly has an 'any' type. - declare var foo; // error at "foo" +!!! error TS7034: Variable 'y' implicitly has type 'any' in some locations where its type cannot be determined. + declare var foo; // error at "foo" ~~~ !!! error TS7005: Variable 'foo' implicitly has an 'any' type. - function func(k) { }; //error at "k" + function func(k) { y }; // error at "k" ~ !!! error TS7006: Parameter 'k' implicitly has an 'any' type. + ~ +!!! error TS7005: Variable 'y' implicitly has an 'any' type. func(x); // this shouldn't be an error diff --git a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js index e3c44e9b78381..5770050d4497d 100644 --- a/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js +++ b/tests/baselines/reference/implicitAnyDeclareVariablesWithoutTypeAndInit.js @@ -1,8 +1,9 @@ //// [implicitAnyDeclareVariablesWithoutTypeAndInit.ts] // this should be an error -var x; // error at "x" -declare var foo; // error at "foo" -function func(k) { }; //error at "k" +var x; // no error, control flow typed +var y; // error because captured +declare var foo; // error at "foo" +function func(k) { y }; // error at "k" func(x); // this shouldn't be an error @@ -13,9 +14,10 @@ var x1: any; var y1 = new x1; //// [implicitAnyDeclareVariablesWithoutTypeAndInit.js] // this should be an error -var x; // error at "x" -function func(k) { } -; //error at "k" +var x; // no error, control flow typed +var y; // error because captured +function func(k) { y; } +; // error at "k" func(x); // this shouldn't be an error var bar = 3; diff --git a/tests/baselines/reference/implicitAnyFunctionInvocationWithAnyArguements.errors.txt b/tests/baselines/reference/implicitAnyFunctionInvocationWithAnyArguements.errors.txt index b15fb779b516c..55108bb803ea8 100644 --- a/tests/baselines/reference/implicitAnyFunctionInvocationWithAnyArguements.errors.txt +++ b/tests/baselines/reference/implicitAnyFunctionInvocationWithAnyArguements.errors.txt @@ -1,4 +1,3 @@ -tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(2,5): error TS7005: Variable 'arg0' implicitly has an 'any' type. tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(3,5): error TS7005: Variable 'anyArray' implicitly has an 'any[]' type. tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(4,13): error TS7008: Member 'v' implicitly has an 'any' type. tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(4,16): error TS7008: Member 'w' implicitly has an 'any' type. @@ -7,11 +6,9 @@ tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(6,16): er tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(10,36): error TS7006: Parameter 'y2' implicitly has an 'any' type. -==== tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts (7 errors) ==== +==== tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts (6 errors) ==== // this should be errors var arg0 = null; // error at "arg0" - ~~~~ -!!! error TS7005: Variable 'arg0' implicitly has an 'any' type. var anyArray = [null, undefined]; // error at array literal ~~~~~~~~ !!! error TS7005: Variable 'anyArray' implicitly has an 'any[]' type. diff --git a/tests/baselines/reference/implicitAnyWidenToAny.errors.txt b/tests/baselines/reference/implicitAnyWidenToAny.errors.txt index 3b86c52c2ea01..95739a450a888 100644 --- a/tests/baselines/reference/implicitAnyWidenToAny.errors.txt +++ b/tests/baselines/reference/implicitAnyWidenToAny.errors.txt @@ -1,17 +1,11 @@ -tests/cases/compiler/implicitAnyWidenToAny.ts(2,5): error TS7005: Variable 'x' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyWidenToAny.ts(3,5): error TS7005: Variable 'x1' implicitly has an 'any' type. tests/cases/compiler/implicitAnyWidenToAny.ts(4,5): error TS7005: Variable 'widenArray' implicitly has an 'any[]' type. tests/cases/compiler/implicitAnyWidenToAny.ts(5,5): error TS7005: Variable 'emptyArray' implicitly has an 'any[]' type. -==== tests/cases/compiler/implicitAnyWidenToAny.ts (4 errors) ==== +==== tests/cases/compiler/implicitAnyWidenToAny.ts (2 errors) ==== // these should be errors var x = null; // error at "x" - ~ -!!! error TS7005: Variable 'x' implicitly has an 'any' type. var x1 = undefined; // error at "x1" - ~~ -!!! error TS7005: Variable 'x1' implicitly has an 'any' type. var widenArray = [null, undefined]; // error at "widenArray" ~~~~~~~~~~ !!! error TS7005: Variable 'widenArray' implicitly has an 'any[]' type. diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherType.js b/tests/baselines/reference/incrementOperatorWithAnyOtherType.js index e99340a53e290..989d4d900d3b0 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherType.js +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherType.js @@ -2,7 +2,7 @@ // ++ operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj = {x:1,y:null}; class A { diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherType.symbols b/tests/baselines/reference/incrementOperatorWithAnyOtherType.symbols index 338ab90506429..2eceb1a243163 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherType.symbols +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherType.symbols @@ -4,7 +4,7 @@ var ANY: any; >ANY : Symbol(ANY, Decl(incrementOperatorWithAnyOtherType.ts, 2, 3)) -var ANY1; +var ANY1: any; >ANY1 : Symbol(ANY1, Decl(incrementOperatorWithAnyOtherType.ts, 3, 3)) var ANY2: any[] = ["", ""]; diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherType.types b/tests/baselines/reference/incrementOperatorWithAnyOtherType.types index 715de620bffaf..13a39410df78b 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherType.types +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherType.types @@ -4,7 +4,7 @@ var ANY: any; >ANY : any -var ANY1; +var ANY1: any; >ANY1 : any var ANY2: any[] = ["", ""]; diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt index 92e639df21e39..4aae7f5b51ea4 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.errors.txt @@ -47,7 +47,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp ==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts (45 errors) ==== // ++ operator on any type - var ANY1; + var ANY1: any; var ANY2: any[] = [1, 2]; var obj: () => {} @@ -58,7 +58,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.js b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.js index 636ca74ba0861..be2726f083b5d 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.js +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherTypeInvalidOperations.js @@ -1,6 +1,6 @@ //// [incrementOperatorWithAnyOtherTypeInvalidOperations.ts] // ++ operator on any type -var ANY1; +var ANY1: any; var ANY2: any[] = [1, 2]; var obj: () => {} @@ -11,7 +11,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/initializePropertiesWithRenamedLet.types b/tests/baselines/reference/initializePropertiesWithRenamedLet.types index 65ea68059a7b9..d6937da8983f8 100644 --- a/tests/baselines/reference/initializePropertiesWithRenamedLet.types +++ b/tests/baselines/reference/initializePropertiesWithRenamedLet.types @@ -10,15 +10,15 @@ if (true) { >x0 : any var obj1 = { x0: x0 }; ->obj1 : { x0: any; } ->{ x0: x0 } : { x0: any; } ->x0 : any ->x0 : any +>obj1 : { x0: undefined; } +>{ x0: x0 } : { x0: undefined; } +>x0 : undefined +>x0 : undefined var obj2 = { x0 }; ->obj2 : { x0: any; } ->{ x0 } : { x0: any; } ->x0 : any +>obj2 : { x0: undefined; } +>{ x0 } : { x0: undefined; } +>x0 : undefined } var x, y, z; diff --git a/tests/baselines/reference/json.stringify.types b/tests/baselines/reference/json.stringify.types index b063b06d8d07c..8ff84885d9c33 100644 --- a/tests/baselines/reference/json.stringify.types +++ b/tests/baselines/reference/json.stringify.types @@ -1,7 +1,7 @@ === tests/cases/compiler/json.stringify.ts === var value = null; ->value : null +>value : any >null : null JSON.stringify(value, undefined, 2); diff --git a/tests/baselines/reference/negateOperatorWithAnyOtherType.errors.txt b/tests/baselines/reference/negateOperatorWithAnyOtherType.errors.txt index f008b4698ed10..03e596aca41c8 100644 --- a/tests/baselines/reference/negateOperatorWithAnyOtherType.errors.txt +++ b/tests/baselines/reference/negateOperatorWithAnyOtherType.errors.txt @@ -5,7 +5,7 @@ tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperator // - operator on any type var ANY: any; - var ANY1; + var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} var obj1 = { x: "", y: () => { }}; @@ -16,7 +16,7 @@ tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperator } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/negateOperatorWithAnyOtherType.js b/tests/baselines/reference/negateOperatorWithAnyOtherType.js index 6a2fe74c7ba7c..eb5f70d8c9c83 100644 --- a/tests/baselines/reference/negateOperatorWithAnyOtherType.js +++ b/tests/baselines/reference/negateOperatorWithAnyOtherType.js @@ -2,7 +2,7 @@ // - operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} var obj1 = { x: "", y: () => { }}; @@ -13,7 +13,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.types b/tests/baselines/reference/nestedBlockScopedBindings3.types index 0de8123861d5b..ca13759bac4f2 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings3.types +++ b/tests/baselines/reference/nestedBlockScopedBindings3.types @@ -31,7 +31,7 @@ function a1() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : undefined >1 : 1 () => x; @@ -53,24 +53,24 @@ function a2() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 } for (let x;;) { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -82,14 +82,14 @@ function a3() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 } switch (1) { @@ -111,14 +111,14 @@ function a4() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 () => x; @@ -145,14 +145,14 @@ function a5() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 () => x; diff --git a/tests/baselines/reference/nestedBlockScopedBindings4.types b/tests/baselines/reference/nestedBlockScopedBindings4.types index 65b5d73db9d85..9e0147f25f7fb 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings4.types +++ b/tests/baselines/reference/nestedBlockScopedBindings4.types @@ -5,24 +5,24 @@ function a0() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 } for (let x;;) { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -33,14 +33,14 @@ function a1() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 () => x; @@ -51,10 +51,10 @@ function a1() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -65,24 +65,24 @@ function a2() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 } for (let x;;) { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 () => x; @@ -98,14 +98,14 @@ function a3() { for (let x; x < 1;) { >x : any >x < 1 : boolean ->x : any +>x : number >1 : 1 x = x + 1; ->x = x + 1 : any ->x : any ->x + 1 : any +>x = x + 1 : number >x : any +>x + 1 : number +>x : number >1 : 1 () => x; @@ -116,10 +116,10 @@ function a3() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 () => x; diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.types b/tests/baselines/reference/nestedBlockScopedBindings6.types index 865dea31e377e..bf38f46d50804 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings6.types +++ b/tests/baselines/reference/nestedBlockScopedBindings6.types @@ -18,10 +18,10 @@ function a0() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -49,10 +49,10 @@ function a1() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 } } @@ -76,10 +76,10 @@ function a2() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 () => x; @@ -111,10 +111,10 @@ function a3() { >x : any x = x + 2; ->x = x + 2 : any ->x : any ->x + 2 : any +>x = x + 2 : number >x : any +>x + 2 : number +>x : number >2 : 2 () => x; diff --git a/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt b/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt index f7e6475b971ca..cedbbc8ed3daa 100644 --- a/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt +++ b/tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt @@ -2,14 +2,10 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,5): error TS1 tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,6): error TS7031: Binding element 'a' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,10): error TS1182: A destructuring declaration must have an initializer. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,11): error TS7031: Binding element 'b' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,15): error TS7005: Variable 'c' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,18): error TS7005: Variable 'd' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,5): error TS1182: A destructuring declaration must have an initializer. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,6): error TS7031: Binding element 'a1' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,23): error TS1182: A destructuring declaration must have an initializer. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,24): error TS7031: Binding element 'b1' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,36): error TS7005: Variable 'c1' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,52): error TS7005: Variable 'd1' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(5,5): error TS1182: A destructuring declaration must have an initializer. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(5,18): error TS1182: A destructuring declaration must have an initializer. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(7,5): error TS1182: A destructuring declaration must have an initializer. @@ -17,12 +13,10 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(7,13): error TS tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(7,25): error TS7008: Member 'b3' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,6): error TS7031: Binding element 'a4' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,26): error TS7031: Binding element 'b4' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,46): error TS7005: Variable 'c4' implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,62): error TS7005: Variable 'd4' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS7031: Binding element 'a5' implicitly has an 'any' type. -==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (22 errors) ==== +==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (16 errors) ==== var [a], {b}, c, d; // error ~~~ !!! error TS1182: A destructuring declaration must have an initializer. @@ -32,10 +26,6 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS !!! error TS1182: A destructuring declaration must have an initializer. ~ !!! error TS7031: Binding element 'b' implicitly has an 'any' type. - ~ -!!! error TS7005: Variable 'c' implicitly has an 'any' type. - ~ -!!! error TS7005: Variable 'd' implicitly has an 'any' type. var [a1 = undefined], {b1 = null}, c1 = undefined, d1 = null; // error ~~~~~~~~~~~~~~~~ @@ -46,10 +36,6 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS !!! error TS1182: A destructuring declaration must have an initializer. ~~ !!! error TS7031: Binding element 'b1' implicitly has an 'any' type. - ~~ -!!! error TS7005: Variable 'c1' implicitly has an 'any' type. - ~~ -!!! error TS7005: Variable 'd1' implicitly has an 'any' type. var [a2]: [any], {b2}: { b2: any }, c2: any, d2: any; ~~~~ @@ -70,10 +56,6 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS !!! error TS7031: Binding element 'a4' implicitly has an 'any' type. ~~ !!! error TS7031: Binding element 'b4' implicitly has an 'any' type. - ~~ -!!! error TS7005: Variable 'c4' implicitly has an 'any' type. - ~~ -!!! error TS7005: Variable 'd4' implicitly has an 'any' type. var [a5 = undefined] = []; // error ~~ diff --git a/tests/baselines/reference/noImplicitAnyForIn.errors.txt b/tests/baselines/reference/noImplicitAnyForIn.errors.txt index 2fb8e5a410303..69b5cd34906fd 100644 --- a/tests/baselines/reference/noImplicitAnyForIn.errors.txt +++ b/tests/baselines/reference/noImplicitAnyForIn.errors.txt @@ -1,11 +1,10 @@ tests/cases/compiler/noImplicitAnyForIn.ts(8,18): error TS7017: Index signature of object type implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyForIn.ts(15,18): error TS7017: Index signature of object type implicitly has an 'any' type. -tests/cases/compiler/noImplicitAnyForIn.ts(21,9): error TS7005: Variable 'b' implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyForIn.ts(29,5): error TS7005: Variable 'n' implicitly has an 'any[][]' type. tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. -==== tests/cases/compiler/noImplicitAnyForIn.ts (5 errors) ==== +==== tests/cases/compiler/noImplicitAnyForIn.ts (4 errors) ==== var x: {}[] = [[1, 2, 3], ["hello"]]; @@ -31,8 +30,6 @@ tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand si for (var a in x) { // Should yield an implicit 'any' error. var b; - ~ -!!! error TS7005: Variable 'b' implicitly has an 'any' type. var c = a || b; } diff --git a/tests/baselines/reference/null.types b/tests/baselines/reference/null.types index 35c084c3cbf40..ab5ae728dea39 100644 --- a/tests/baselines/reference/null.types +++ b/tests/baselines/reference/null.types @@ -5,10 +5,10 @@ var x=null; >null : null var y=3+x; ->y : any ->3+x : any +>y : number +>3+x : number >3 : 3 ->x : any +>x : null var z=3+null; >z : number diff --git a/tests/baselines/reference/objectLiteralShorthandProperties.types b/tests/baselines/reference/objectLiteralShorthandProperties.types index 4f4482906aa50..168fcc07af784 100644 --- a/tests/baselines/reference/objectLiteralShorthandProperties.types +++ b/tests/baselines/reference/objectLiteralShorthandProperties.types @@ -5,35 +5,35 @@ var a, b, c; >c : any var x1 = { ->x1 : { a: any; } ->{ a} : { a: any; } +>x1 : { a: undefined; } +>{ a} : { a: undefined; } a ->a : any +>a : undefined }; var x2 = { ->x2 : { a: any; } ->{ a,} : { a: any; } +>x2 : { a: undefined; } +>{ a,} : { a: undefined; } a, ->a : any +>a : undefined } var x3 = { >x3 : any ->{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } +>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: undefined; c: undefined; d(): void; x3: any; parent: any; } a: 0, >a : number >0 : 0 b, ->b : any +>b : undefined c, ->c : any +>c : undefined d() { }, >d : () => void diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types index 1565be04625b3..80cbe304040b9 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesES6.types @@ -5,35 +5,35 @@ var a, b, c; >c : any var x1 = { ->x1 : { a: any; } ->{ a} : { a: any; } +>x1 : { a: undefined; } +>{ a} : { a: undefined; } a ->a : any +>a : undefined }; var x2 = { ->x2 : { a: any; } ->{ a,} : { a: any; } +>x2 : { a: undefined; } +>{ a,} : { a: undefined; } a, ->a : any +>a : undefined } var x3 = { >x3 : any ->{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; } +>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: undefined; c: undefined; d(): void; x3: any; parent: any; } a: 0, >a : number >0 : 0 b, ->b : any +>b : undefined c, ->c : any +>c : undefined d() { }, >d : () => void diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types index 234375fb46dda..ca7d65c9c3495 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator1.types @@ -10,12 +10,12 @@ function f1() { if (a < b || b > (c + 1)) { } >a < b || b > (c + 1) : boolean >a < b : boolean ->a : any ->b : any +>a : undefined +>b : undefined >b > (c + 1) : boolean ->b : any ->(c + 1) : any ->c + 1 : any ->c : any +>b : undefined +>(c + 1) : number +>c + 1 : number +>c : undefined >1 : 1 } diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types index ed3b4b903bb86..f4c1c2ac69080 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator2.types @@ -10,12 +10,12 @@ function f() { if (a < b && b > (c + 1)) { } >a < b && b > (c + 1) : boolean >a < b : boolean ->a : any ->b : any +>a : undefined +>b : undefined >b > (c + 1) : boolean ->b : any ->(c + 1) : any ->c + 1 : any ->c : any +>b : undefined +>(c + 1) : number +>c + 1 : number +>c : undefined >1 : 1 } diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types index 61601d8bdf653..b112965634236 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator3.types @@ -10,13 +10,13 @@ function f() { if (a < b && b < (c + 1)) { } >a < b && b < (c + 1) : boolean >a < b : boolean ->a : any ->b : any +>a : undefined +>b : undefined >b < (c + 1) : boolean ->b : any ->(c + 1) : any ->c + 1 : any ->c : any +>b : undefined +>(c + 1) : number +>c + 1 : number +>c : undefined >1 : 1 } diff --git a/tests/baselines/reference/parserharness.errors.txt b/tests/baselines/reference/parserharness.errors.txt index d3d0c4056a1d5..90ac8e0e76027 100644 --- a/tests/baselines/reference/parserharness.errors.txt +++ b/tests/baselines/reference/parserharness.errors.txt @@ -25,6 +25,9 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(776,42): e tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(781,23): error TS2503: Cannot find namespace 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(794,49): error TS2304: Cannot find name 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(795,49): error TS2304: Cannot find name 'TypeScript'. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(820,31): error TS2339: Property 'length' does not exist on type 'null'. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(976,28): error TS2339: Property 'length' does not exist on type 'null'. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(977,82): error TS2339: Property 'join' does not exist on type 'null'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(987,53): error TS2304: Cannot find name 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(987,89): error TS2304: Cannot find name 'TypeScript'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(987,115): error TS2503: Cannot find namespace 'TypeScript'. @@ -110,7 +113,7 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(1787,68): tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): error TS2304: Cannot find name 'Diff'. -==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (110 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (113 errors) ==== // // Copyright (c) Microsoft Corporation. All rights reserved. // @@ -985,6 +988,8 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): }) return errors.length === 0; + ~~~~~~ +!!! error TS2339: Property 'length' does not exist on type 'null'. } public isSubtypeOf(other: Type) { @@ -1141,7 +1146,11 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): }) if (errors.length > 0) + ~~~~~~ +!!! error TS2339: Property 'length' does not exist on type 'null'. throw new Error("Type definition contains errors: " + errors.join(",")); + ~~~~ +!!! error TS2339: Property 'join' does not exist on type 'null'. var matchingIdentifiers: Type[] = []; diff --git a/tests/baselines/reference/protoAsIndexInIndexExpression.types b/tests/baselines/reference/protoAsIndexInIndexExpression.types index b761aa2c7a70a..6d1374d1f78f7 100644 --- a/tests/baselines/reference/protoAsIndexInIndexExpression.types +++ b/tests/baselines/reference/protoAsIndexInIndexExpression.types @@ -14,11 +14,11 @@ var WorkspacePrototype = { } }; WorkspacePrototype['__proto__'] = EntityPrototype; ->WorkspacePrototype['__proto__'] = EntityPrototype : any +>WorkspacePrototype['__proto__'] = EntityPrototype : undefined >WorkspacePrototype['__proto__'] : any >WorkspacePrototype : { serialize: () => any; } >'__proto__' : "___proto__" ->EntityPrototype : any +>EntityPrototype : undefined var o = { >o : { "__proto__": number; } diff --git a/tests/baselines/reference/strictNullChecksNoWidening.types b/tests/baselines/reference/strictNullChecksNoWidening.types index a544f9cef94a4..375977ae37514 100644 --- a/tests/baselines/reference/strictNullChecksNoWidening.types +++ b/tests/baselines/reference/strictNullChecksNoWidening.types @@ -1,11 +1,11 @@ === tests/cases/conformance/types/typeRelationships/widenedTypes/strictNullChecksNoWidening.ts === var a1 = null; ->a1 : null +>a1 : any >null : null var a2 = undefined; ->a2 : undefined +>a2 : any >undefined : undefined var a3 = void 0; diff --git a/tests/baselines/reference/tsxEmit1.types b/tests/baselines/reference/tsxEmit1.types index 84f00b4758ab6..c3ca7a2b1b015 100644 --- a/tests/baselines/reference/tsxEmit1.types +++ b/tests/baselines/reference/tsxEmit1.types @@ -61,7 +61,7 @@ var selfClosed7 =
; >
: JSX.Element >div : any >x : any ->p : any +>p : undefined >y : any var openClosed1 =
; @@ -82,7 +82,7 @@ var openClosed3 =
{p}
; >
{p}
: JSX.Element >div : any >n : any ->p : any +>p : undefined >div : any var openClosed4 =
{p < p}
; @@ -91,8 +91,8 @@ var openClosed4 =
{p < p}
; >div : any >n : any >p < p : boolean ->p : any ->p : any +>p : undefined +>p : undefined >div : any var openClosed5 =
{p > p}
; @@ -101,8 +101,8 @@ var openClosed5 =
{p > p}
; >div : any >n : any >p > p : boolean ->p : any ->p : any +>p : undefined +>p : undefined >div : any class SomeClass { @@ -180,7 +180,7 @@ var whitespace2 =
{p}
; >whitespace2 : JSX.Element >
{p}
: JSX.Element >div : any ->p : any +>p : undefined >div : any var whitespace3 =
@@ -189,7 +189,7 @@ var whitespace3 =
>div : any {p} ->p : any +>p : undefined
; >div : any diff --git a/tests/baselines/reference/tsxEmit2.types b/tests/baselines/reference/tsxEmit2.types index 5b267d8b80262..d306dc9ffe057 100644 --- a/tests/baselines/reference/tsxEmit2.types +++ b/tests/baselines/reference/tsxEmit2.types @@ -22,16 +22,16 @@ var spreads1 =
{p2}
; >spreads1 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any ->p2 : any +>p1 : undefined +>p2 : undefined >div : any var spreads2 =
{p2}
; >spreads2 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any ->p2 : any +>p1 : undefined +>p2 : undefined >div : any var spreads3 =
{p2}
; @@ -39,19 +39,19 @@ var spreads3 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p3 : any ->p1 : any ->p2 : any +>p3 : undefined +>p1 : undefined +>p2 : undefined >div : any var spreads4 =
{p2}
; >spreads4 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any +>p1 : undefined >x : any ->p3 : any ->p2 : any +>p3 : undefined +>p2 : undefined >div : any var spreads5 =
{p2}
; @@ -59,10 +59,10 @@ var spreads5 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p2 : any ->p1 : any +>p2 : undefined +>p1 : undefined >y : any ->p3 : any ->p2 : any +>p3 : undefined +>p2 : undefined >div : any diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.js b/tests/baselines/reference/tsxGenericArrowFunctionParsing.js index e77e832cb0af5..7dbb2477db577 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.js +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.js @@ -3,7 +3,7 @@ declare module JSX { interface Element { isElement; } } -var T, T1, T2; +var T: any, T1: any, T2: any; // This is an element var x1 = () => {}; diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols b/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols index 6d90c583a66e3..2d3c1f18d48d2 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols @@ -7,10 +7,10 @@ declare module JSX { >isElement : Symbol(Element.isElement, Decl(file.tsx, 1, 20)) } -var T, T1, T2; +var T: any, T1: any, T2: any; >T : Symbol(T, Decl(file.tsx, 4, 3)) ->T1 : Symbol(T1, Decl(file.tsx, 4, 6)) ->T2 : Symbol(T2, Decl(file.tsx, 4, 10)) +>T1 : Symbol(T1, Decl(file.tsx, 4, 11)) +>T2 : Symbol(T2, Decl(file.tsx, 4, 20)) // This is an element var x1 = () => {}; diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.types b/tests/baselines/reference/tsxGenericArrowFunctionParsing.types index 693f920195dd3..0f746a071363e 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.types +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.types @@ -7,7 +7,7 @@ declare module JSX { >isElement : any } -var T, T1, T2; +var T: any, T1: any, T2: any; >T : any >T1 : any >T2 : any diff --git a/tests/baselines/reference/tsxReactEmit1.types b/tests/baselines/reference/tsxReactEmit1.types index 8eb14e9196365..b2cb2f73eba05 100644 --- a/tests/baselines/reference/tsxReactEmit1.types +++ b/tests/baselines/reference/tsxReactEmit1.types @@ -63,7 +63,7 @@ var selfClosed7 =
; >
: JSX.Element >div : any >x : any ->p : any +>p : undefined >y : any >b : any @@ -85,7 +85,7 @@ var openClosed3 =
{p}
; >
{p}
: JSX.Element >div : any >n : any ->p : any +>p : undefined >div : any var openClosed4 =
{p < p}
; @@ -94,8 +94,8 @@ var openClosed4 =
{p < p}
; >div : any >n : any >p < p : boolean ->p : any ->p : any +>p : undefined +>p : undefined >div : any var openClosed5 =
{p > p}
; @@ -105,8 +105,8 @@ var openClosed5 =
{p > p}
; >n : any >b : any >p > p : boolean ->p : any ->p : any +>p : undefined +>p : undefined >div : any class SomeClass { @@ -184,7 +184,7 @@ var whitespace2 =
{p}
; >whitespace2 : JSX.Element >
{p}
: JSX.Element >div : any ->p : any +>p : undefined >div : any var whitespace3 =
@@ -193,7 +193,7 @@ var whitespace3 =
>div : any {p} ->p : any +>p : undefined
; >div : any diff --git a/tests/baselines/reference/tsxReactEmit2.types b/tests/baselines/reference/tsxReactEmit2.types index 928eeecadfac9..b05764e996fc3 100644 --- a/tests/baselines/reference/tsxReactEmit2.types +++ b/tests/baselines/reference/tsxReactEmit2.types @@ -24,16 +24,16 @@ var spreads1 =
{p2}
; >spreads1 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any ->p2 : any +>p1 : undefined +>p2 : undefined >div : any var spreads2 =
{p2}
; >spreads2 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any ->p2 : any +>p1 : undefined +>p2 : undefined >div : any var spreads3 =
{p2}
; @@ -41,19 +41,19 @@ var spreads3 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p3 : any ->p1 : any ->p2 : any +>p3 : undefined +>p1 : undefined +>p2 : undefined >div : any var spreads4 =
{p2}
; >spreads4 : JSX.Element >
{p2}
: JSX.Element >div : any ->p1 : any +>p1 : undefined >x : any ->p3 : any ->p2 : any +>p3 : undefined +>p2 : undefined >div : any var spreads5 =
{p2}
; @@ -61,10 +61,10 @@ var spreads5 =
{p2}
; >
{p2}
: JSX.Element >div : any >x : any ->p2 : any ->p1 : any +>p2 : undefined +>p1 : undefined >y : any ->p3 : any ->p2 : any +>p3 : undefined +>p2 : undefined >div : any diff --git a/tests/baselines/reference/tsxReactEmit5.types b/tests/baselines/reference/tsxReactEmit5.types index fb1c6594f3035..73e7e6ff3913e 100644 --- a/tests/baselines/reference/tsxReactEmit5.types +++ b/tests/baselines/reference/tsxReactEmit5.types @@ -32,6 +32,6 @@ var spread1 =
; >
: JSX.Element >div : any >x : any ->foo : any +>foo : undefined >y : any diff --git a/tests/baselines/reference/tsxReactEmit6.types b/tests/baselines/reference/tsxReactEmit6.types index b8a307eb9d765..ae56de052cc44 100644 --- a/tests/baselines/reference/tsxReactEmit6.types +++ b/tests/baselines/reference/tsxReactEmit6.types @@ -35,7 +35,7 @@ namespace M { >
: JSX.Element >div : any >x : any ->foo : any +>foo : undefined >y : any // Quotes diff --git a/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.errors.txt b/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.errors.txt new file mode 100644 index 0000000000000..3f8cdf56c3dbc --- /dev/null +++ b/tests/baselines/reference/typeCheckObjectCreationExpressionWithUndefinedCallResolutionData.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/file1.ts(3,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. + + +==== tests/cases/compiler/file2.ts (0 errors) ==== + import f = require('./file1'); + f.foo(); + +==== tests/cases/compiler/file1.ts (1 errors) ==== + export function foo() { + var classes = undefined; + return new classes(null); + ~~~~~~~~~~~~~~~~~ +!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. + } + \ No newline at end of file diff --git a/tests/baselines/reference/unusedSwitchStatment.errors.txt b/tests/baselines/reference/unusedSwitchStatment.errors.txt index a22c252f60d52..591e9deca7a21 100644 --- a/tests/baselines/reference/unusedSwitchStatment.errors.txt +++ b/tests/baselines/reference/unusedSwitchStatment.errors.txt @@ -4,9 +4,10 @@ tests/cases/compiler/unusedSwitchStatment.ts(7,15): error TS6133: 'c' is declare tests/cases/compiler/unusedSwitchStatment.ts(10,13): error TS6133: 'z' is declared but never used. tests/cases/compiler/unusedSwitchStatment.ts(15,10): error TS2678: Type '0' is not comparable to type '2'. tests/cases/compiler/unusedSwitchStatment.ts(17,10): error TS2678: Type '1' is not comparable to type '2'. +tests/cases/compiler/unusedSwitchStatment.ts(18,9): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -==== tests/cases/compiler/unusedSwitchStatment.ts (6 errors) ==== +==== tests/cases/compiler/unusedSwitchStatment.ts (7 errors) ==== switch (1) { case 0: @@ -37,4 +38,6 @@ tests/cases/compiler/unusedSwitchStatment.ts(17,10): error TS2678: Type '1' is n ~ !!! error TS2678: Type '1' is not comparable to type '2'. x++; + ~ +!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. } \ No newline at end of file diff --git a/tests/cases/compiler/anyPlusAny1.ts b/tests/cases/compiler/anyPlusAny1.ts index 084dcc02be33d..c1bee9b97b06c 100644 --- a/tests/cases/compiler/anyPlusAny1.ts +++ b/tests/cases/compiler/anyPlusAny1.ts @@ -1,3 +1,3 @@ -var x; +var x: any; x.name = "hello"; var z = x + x; \ No newline at end of file diff --git a/tests/cases/compiler/controlFlowLetVar.ts b/tests/cases/compiler/controlFlowLetVar.ts new file mode 100644 index 0000000000000..a56a3382642de --- /dev/null +++ b/tests/cases/compiler/controlFlowLetVar.ts @@ -0,0 +1,129 @@ +// @strictNullChecks: true + +declare let cond: boolean; + +// CFA for 'let' with no type annotation and initializer +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'let' with with type annotation +function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// CFA for 'var' with no type annotation and initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'var' with with type annotation +function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// No CFA for captured outer variables +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + function f() { + const z = x; // any + } +} + +// No CFA for captured outer variables +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + const f = () => { + const z = x; // any + }; +} \ No newline at end of file diff --git a/tests/cases/compiler/controlFlowNoImplicitAny.ts b/tests/cases/compiler/controlFlowNoImplicitAny.ts new file mode 100644 index 0000000000000..a388a495f08eb --- /dev/null +++ b/tests/cases/compiler/controlFlowNoImplicitAny.ts @@ -0,0 +1,130 @@ +// @strictNullChecks: true +// @noImplicitAny: true + +declare let cond: boolean; + +// CFA for 'let' with no type annotation and initializer +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'undefined' initializer +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'let' with no type annotation and 'null' initializer +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'let' with with type annotation +function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// CFA for 'var' with no type annotation and initializer +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'undefined' initializer +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined +} + +// CFA for 'var' with no type annotation and 'null' initializer +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | null +} + +// No CFA for 'var' with with type annotation +function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // any +} + +// No CFA for captured outer variables +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + function f() { + const z = x; // any + } +} + +// No CFA for captured outer variables +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; // string | number | undefined + const f = () => { + const z = x; // any + }; +} \ No newline at end of file diff --git a/tests/cases/compiler/es5-asyncFunctionTryStatements.ts b/tests/cases/compiler/es5-asyncFunctionTryStatements.ts index 11459295f47cd..0d14b5f4242c2 100644 --- a/tests/cases/compiler/es5-asyncFunctionTryStatements.ts +++ b/tests/cases/compiler/es5-asyncFunctionTryStatements.ts @@ -1,10 +1,10 @@ // @lib: es5,es2015.promise // @noEmitHelpers: true // @target: ES5 -declare var x, y, z, a, b, c; +declare var x: any, y: any, z: any, a: any, b: any, c: any; async function tryCatch0() { - var x, y; + var x: any, y: any; try { x; } @@ -14,7 +14,7 @@ async function tryCatch0() { } async function tryCatch1() { - var x, y; + var x: any, y: any; try { await x; } @@ -24,7 +24,7 @@ async function tryCatch1() { } async function tryCatch2() { - var x, y; + var x: any, y: any; try { x; } @@ -34,7 +34,7 @@ async function tryCatch2() { } async function tryCatch3(): Promise { - var x, y; + var x: any, y: any; try { await x; } @@ -43,7 +43,7 @@ async function tryCatch3(): Promise { } } async function tryFinally0() { - var x, y; + var x: any, y: any; try { x; } @@ -53,7 +53,7 @@ async function tryFinally0() { } async function tryFinally1() { - var x, y; + var x: any, y: any; try { await x; } @@ -63,7 +63,7 @@ async function tryFinally1() { } async function tryFinally2() { - var x, y; + var x: any, y: any; try { x; } @@ -73,7 +73,7 @@ async function tryFinally2() { } async function tryCatchFinally0() { - var x, y, z; + var x: any, y: any, z: any; try { x; } @@ -86,7 +86,7 @@ async function tryCatchFinally0() { } async function tryCatchFinally1() { - var x, y, z; + var x: any, y: any, z: any; try { await x; } @@ -99,7 +99,7 @@ async function tryCatchFinally1() { } async function tryCatchFinally2() { - var x, y, z; + var x: any, y: any, z: any; try { x; } @@ -112,7 +112,7 @@ async function tryCatchFinally2() { } async function tryCatchFinally3() { - var x, y, z; + var x: any, y: any, z: any; try { x; } diff --git a/tests/cases/compiler/expr.ts b/tests/cases/compiler/expr.ts index b76aba8810317..8d6f7beed7ece 100644 --- a/tests/cases/compiler/expr.ts +++ b/tests/cases/compiler/expr.ts @@ -6,7 +6,7 @@ enum E { } function f() { - var a; + var a: any; var n=3; var s=""; var b=false; diff --git a/tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts b/tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts index 88812001c9efb..a84ab03f4b3fe 100644 --- a/tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts +++ b/tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts @@ -1,8 +1,9 @@ // @noimplicitany: true // this should be an error -var x; // error at "x" -declare var foo; // error at "foo" -function func(k) { }; //error at "k" +var x; // no error, control flow typed +var y; // error because captured +declare var foo; // error at "foo" +function func(k) { y }; // error at "k" func(x); // this shouldn't be an error diff --git a/tests/cases/conformance/Symbols/ES5SymbolProperty2.ts b/tests/cases/conformance/Symbols/ES5SymbolProperty2.ts index 07c95eb27d99e..6bfce5fc58ddb 100644 --- a/tests/cases/conformance/Symbols/ES5SymbolProperty2.ts +++ b/tests/cases/conformance/Symbols/ES5SymbolProperty2.ts @@ -1,6 +1,6 @@ //@target: ES5 module M { - var Symbol; + var Symbol: any; export class C { [Symbol.iterator]() { } diff --git a/tests/cases/conformance/Symbols/ES5SymbolProperty3.ts b/tests/cases/conformance/Symbols/ES5SymbolProperty3.ts index 262e47557f8b9..a6eecc721241d 100644 --- a/tests/cases/conformance/Symbols/ES5SymbolProperty3.ts +++ b/tests/cases/conformance/Symbols/ES5SymbolProperty3.ts @@ -1,5 +1,5 @@ //@target: ES5 -var Symbol; +var Symbol: any; class C { [Symbol.iterator]() { } diff --git a/tests/cases/conformance/es6/for-ofStatements/for-of3.ts b/tests/cases/conformance/es6/for-ofStatements/for-of3.ts index 7eb1e1fd220fd..850daee83683e 100644 --- a/tests/cases/conformance/es6/for-ofStatements/for-of3.ts +++ b/tests/cases/conformance/es6/for-ofStatements/for-of3.ts @@ -1,3 +1,3 @@ //@target: ES6 -var v; +var v: any; for (v++ of []) { } \ No newline at end of file diff --git a/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts b/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts index 02e6acfa685fc..7339704fc6583 100644 --- a/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts +++ b/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts @@ -1,4 +1,4 @@ -var value; +var value: any; // identifiers: variable and parameter var x1: number; diff --git a/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts b/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts index 0eac581bfe418..176c2043344a4 100644 --- a/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts +++ b/tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts @@ -1,5 +1,5 @@ // expected error for all the LHS of compound assignments (arithmetic and addition) -var value; +var value: any; // this class C { diff --git a/tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts b/tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts index e5118d18551b8..13f5ce14e7d0d 100644 --- a/tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts +++ b/tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts @@ -1,7 +1,7 @@ // @target: es5 // Error: early syntax error using ES7 SimpleUnaryExpression on left-hand side without () -var temp; +var temp: any; delete --temp ** 3; delete ++temp ** 3; diff --git a/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts b/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts index de5dbf6d747e1..91db91a3a9b41 100644 --- a/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts +++ b/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts @@ -1,4 +1,4 @@ -var value; +var value: any; // identifiers: variable and parameter var x1: number; diff --git a/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts b/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts index 467a750b418a4..30b8df4268a39 100644 --- a/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts +++ b/tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts @@ -1,5 +1,5 @@ // expected error for all the LHS of assignments -var value; +var value: any; // this class C { diff --git a/tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts b/tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts index 62311ee75c9e3..8eb50d2f64ad5 100644 --- a/tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts +++ b/tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts @@ -1,7 +1,7 @@ // @allowUnusedLabels: true // expected error for all the LHS of compound assignments (arithmetic and addition) -var value; +var value: any; // this class C { diff --git a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherType.ts b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherType.ts index 4ca37129f60a1..f8efeb81ecb24 100644 --- a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherType.ts @@ -1,7 +1,7 @@ // -- operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj = {x:1,y:null}; class A { diff --git a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts index 10dc05a4a336e..d5dd62de442bb 100644 --- a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts +++ b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts @@ -1,5 +1,5 @@ // -- operator on any type -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} @@ -10,7 +10,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherType.ts b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherType.ts index f1fa058745fbc..09f272442e1ee 100644 --- a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherType.ts @@ -1,7 +1,7 @@ // ++ operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj = {x:1,y:null}; class A { diff --git a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts index 2e6b14d77276a..397024d45d631 100644 --- a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts +++ b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts @@ -1,5 +1,5 @@ // ++ operator on any type -var ANY1; +var ANY1: any; var ANY2: any[] = [1, 2]; var obj: () => {} @@ -10,7 +10,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithAnyOtherType.ts b/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithAnyOtherType.ts index 189f1f000d81f..d29b1a845eba2 100644 --- a/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithAnyOtherType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithAnyOtherType.ts @@ -1,7 +1,7 @@ // - operator on any type var ANY: any; -var ANY1; +var ANY1: any; var ANY2: any[] = ["", ""]; var obj: () => {} var obj1 = { x: "", y: () => { }}; @@ -12,7 +12,7 @@ function foo(): any { } class A { public a: any; - static foo() { + static foo(): any { var a; return a; } diff --git a/tests/cases/conformance/jsx/tsxGenericArrowFunctionParsing.tsx b/tests/cases/conformance/jsx/tsxGenericArrowFunctionParsing.tsx index b3d3d34020a98..deb7ba57b5de3 100644 --- a/tests/cases/conformance/jsx/tsxGenericArrowFunctionParsing.tsx +++ b/tests/cases/conformance/jsx/tsxGenericArrowFunctionParsing.tsx @@ -4,7 +4,7 @@ declare module JSX { interface Element { isElement; } } -var T, T1, T2; +var T: any, T1: any, T2: any; // This is an element var x1 = () => {}; diff --git a/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser537152.ts b/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser537152.ts deleted file mode 100644 index d418f92b7ecb0..0000000000000 --- a/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser537152.ts +++ /dev/null @@ -1,2 +0,0 @@ -var t; -var y = t.e1; diff --git a/tests/cases/conformance/statements/for-inStatements/for-inStatements.ts b/tests/cases/conformance/statements/for-inStatements/for-inStatements.ts index 1ff19b3e412c0..89cc0314d365d 100644 --- a/tests/cases/conformance/statements/for-inStatements/for-inStatements.ts +++ b/tests/cases/conformance/statements/for-inStatements/for-inStatements.ts @@ -14,7 +14,7 @@ for (var x in fn()) { } for (var x in /[a-z]/) { } for (var x in new Date()) { } -var c, d, e; +var c: any, d: any, e: any; for (var x in c || d) { } for (var x in e ? c : d) { }