diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e4ad33398871d..ca562a5c35349 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2520,9 +2520,9 @@ namespace ts { // Return the inferred type for a variable, parameter, or property declaration function getTypeForVariableLikeDeclaration(declaration: VariableLikeDeclaration): Type { - // A variable declared in a for..in statement is always of type any + // A variable declared in a for..in statement is always of type string if (declaration.parent.parent.kind === SyntaxKind.ForInStatement) { - return anyType; + return stringType; } if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement) { @@ -8563,6 +8563,56 @@ namespace ts { return true; } + /** + * Return the symbol of the for-in variable declared or referenced by the given for-in statement. + */ + function getForInVariableSymbol(node: ForInStatement): Symbol { + const initializer = node.initializer; + if (initializer.kind === SyntaxKind.VariableDeclarationList) { + const variable = (initializer).declarations[0]; + if (variable && !isBindingPattern(variable.name)) { + return getSymbolOfNode(variable); + } + } + else if (initializer.kind === SyntaxKind.Identifier) { + return getResolvedSymbol(initializer); + } + return undefined; + } + + /** + * Return true if the given type is considered to have numeric property names. + */ + function hasNumericPropertyNames(type: Type) { + return getIndexTypeOfType(type, IndexKind.Number) && !getIndexTypeOfType(type, IndexKind.String); + } + + /** + * Return true if given node is an expression consisting of an identifier (possibly parenthesized) + * that references a for-in variable for an object with numeric property names. + */ + function isForInVariableForNumericPropertyNames(expr: Expression) { + const e = skipParenthesizedNodes(expr); + if (e.kind === SyntaxKind.Identifier) { + const symbol = getResolvedSymbol(e); + if (symbol.flags & SymbolFlags.Variable) { + let child: Node = expr; + let node = expr.parent; + while (node) { + if (node.kind === SyntaxKind.ForInStatement && + child === (node).statement && + getForInVariableSymbol(node) === symbol && + hasNumericPropertyNames(checkExpression((node).expression))) { + return true; + } + child = node; + node = node.parent; + } + } + } + return false; + } + function checkIndexedAccess(node: ElementAccessExpression): Type { // Grammar checking if (!node.argumentExpression) { @@ -8623,7 +8673,7 @@ namespace ts { if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) { // Try to use a number indexer. - if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike)) { + if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike) || isForInVariableForNumericPropertyNames(node.argumentExpression)) { const numberIndexType = getIndexTypeOfType(objectType, IndexKind.Number); if (numberIndexType) { return numberIndexType; @@ -8638,7 +8688,9 @@ namespace ts { // Fall back to any. if (compilerOptions.noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !isTypeAny(objectType)) { - error(node, Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); + error(node, getIndexTypeOfType(objectType, IndexKind.Number) ? + Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number : + Diagnostics.Index_signature_of_object_type_implicitly_has_an_any_type); } return anyType; @@ -12697,7 +12749,8 @@ namespace ts { } // For a binding pattern, validate the initializer and exit if (isBindingPattern(node.name)) { - if (node.initializer) { + // Don't validate for-in initializer as it is already an error + if (node.initializer && node.parent.parent.kind !== SyntaxKind.ForInStatement) { checkTypeAssignableTo(checkExpressionCached(node.initializer), getWidenedTypeForVariableLikeDeclaration(node), node, /*headMessage*/ undefined); checkParameterInitializer(node); } @@ -12707,7 +12760,8 @@ namespace ts { const type = getTypeOfVariableOrParameterOrProperty(symbol); if (node === symbol.valueDeclaration) { // Node is the primary declaration of the symbol, just validate the initializer - if (node.initializer) { + // Don't validate for-in initializer as it is already an error + if (node.initializer && node.parent.parent.kind !== SyntaxKind.ForInStatement) { checkTypeAssignableTo(checkExpressionCached(node.initializer), type, node, /*headMessage*/ undefined); checkParameterInitializer(node); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f7268d6d9908b..4a0a1dba5ac58 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2422,6 +2422,10 @@ "category": "Error", "code": 7013 }, + "Element implicitly has an 'any' type because index expression is not of type 'number'.": { + "category": "Error", + "code": 7015 + }, "Property '{0}' implicitly has type 'any', because its 'set' accessor lacks a type annotation.": { "category": "Error", "code": 7016 diff --git a/tests/baselines/reference/capturedLetConstInLoop1.types b/tests/baselines/reference/capturedLetConstInLoop1.types index c68f2422f4346..bed3db55d7cf2 100644 --- a/tests/baselines/reference/capturedLetConstInLoop1.types +++ b/tests/baselines/reference/capturedLetConstInLoop1.types @@ -1,18 +1,18 @@ === tests/cases/compiler/capturedLetConstInLoop1.ts === //==== let for (let x in {}) { ->x : any +>x : string >{} : {} (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => string +>function() { return x} : () => string +>x : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string } for (let x of []) { @@ -216,18 +216,18 @@ for (let y = 0; y < 1; ++y) { //=========const for (const x in {}) { ->x : any +>x : string >{} : {} (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => string +>function() { return x} : () => string +>x : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string } for (const x of []) { diff --git a/tests/baselines/reference/capturedLetConstInLoop1_ES6.types b/tests/baselines/reference/capturedLetConstInLoop1_ES6.types index 5e25e1f930d47..47b125866849c 100644 --- a/tests/baselines/reference/capturedLetConstInLoop1_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop1_ES6.types @@ -1,18 +1,18 @@ === tests/cases/compiler/capturedLetConstInLoop1_ES6.ts === //==== let for (let x in {}) { ->x : any +>x : string >{} : {} (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => string +>function() { return x} : () => string +>x : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string } for (let x of []) { @@ -216,18 +216,18 @@ for (let y = 0; y < 1; ++y) { //=========const for (const x in {}) { ->x : any +>x : string >{} : {} (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => string +>function() { return x} : () => string +>x : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string } for (const x of []) { diff --git a/tests/baselines/reference/capturedLetConstInLoop2.types b/tests/baselines/reference/capturedLetConstInLoop2.types index 5108fc399eee2..2872eb4c763f8 100644 --- a/tests/baselines/reference/capturedLetConstInLoop2.types +++ b/tests/baselines/reference/capturedLetConstInLoop2.types @@ -37,7 +37,7 @@ function foo0_1(x) { >x : any for (let x in []) { ->x : any +>x : string >[] : undefined[] let a = arguments.length; @@ -47,17 +47,17 @@ function foo0_1(x) { >length : number (function() { return x + a }); ->(function() { return x + a }) : () => any ->function() { return x + a } : () => any ->x + a : any ->x : any +>(function() { return x + a }) : () => string +>function() { return x + a } : () => string +>x + a : string +>x : string >a : number (() => x + a); ->(() => x + a) : () => any ->() => x + a : () => any ->x + a : any ->x : any +>(() => x + a) : () => string +>() => x + a : () => string +>x + a : string +>x : string >a : number } } @@ -400,7 +400,7 @@ function foo0_1_c(x) { >x : any for (const x in []) { ->x : any +>x : string >[] : undefined[] const a = arguments.length; @@ -410,17 +410,17 @@ function foo0_1_c(x) { >length : number (function() { return x + a }); ->(function() { return x + a }) : () => any ->function() { return x + a } : () => any ->x + a : any ->x : any +>(function() { return x + a }) : () => string +>function() { return x + a } : () => string +>x + a : string +>x : string >a : number (() => x + a); ->(() => x + a) : () => any ->() => x + a : () => any ->x + a : any ->x : any +>(() => x + a) : () => string +>() => x + a : () => string +>x + a : string +>x : string >a : number } } diff --git a/tests/baselines/reference/capturedLetConstInLoop2_ES6.types b/tests/baselines/reference/capturedLetConstInLoop2_ES6.types index 9fea265da44ba..8a4d9c826285e 100644 --- a/tests/baselines/reference/capturedLetConstInLoop2_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop2_ES6.types @@ -36,7 +36,7 @@ function foo0_1(x) { >x : any for (let x in []) { ->x : any +>x : string >[] : undefined[] let a = arguments.length; @@ -46,17 +46,17 @@ function foo0_1(x) { >length : number (function() { return x + a }); ->(function() { return x + a }) : () => any ->function() { return x + a } : () => any ->x + a : any ->x : any +>(function() { return x + a }) : () => string +>function() { return x + a } : () => string +>x + a : string +>x : string >a : number (() => x + a); ->(() => x + a) : () => any ->() => x + a : () => any ->x + a : any ->x : any +>(() => x + a) : () => string +>() => x + a : () => string +>x + a : string +>x : string >a : number } } @@ -399,7 +399,7 @@ function foo0_1_c(x) { >x : any for (const x in []) { ->x : any +>x : string >[] : undefined[] const a = arguments.length; @@ -409,17 +409,17 @@ function foo0_1_c(x) { >length : number (function() { return x + a }); ->(function() { return x + a }) : () => any ->function() { return x + a } : () => any ->x + a : any ->x : any +>(function() { return x + a }) : () => string +>function() { return x + a } : () => string +>x + a : string +>x : string >a : number (() => x + a); ->(() => x + a) : () => any ->() => x + a : () => any ->x + a : any ->x : any +>(() => x + a) : () => string +>() => x + a : () => string +>x + a : string +>x : string >a : number } } diff --git a/tests/baselines/reference/capturedLetConstInLoop3.types b/tests/baselines/reference/capturedLetConstInLoop3.types index 51646f5a98b41..9c0c188b7272b 100644 --- a/tests/baselines/reference/capturedLetConstInLoop3.types +++ b/tests/baselines/reference/capturedLetConstInLoop3.types @@ -42,32 +42,32 @@ function foo0_1(x) { >x : any for (let x in []) { ->x : any +>x : string >[] : undefined[] var v = x; ->v : any ->x : any +>v : string +>x : string (function() { return x + v }); ->(function() { return x + v }) : () => any ->function() { return x + v } : () => any ->x + v : any ->x : any ->v : any +>(function() { return x + v }) : () => string +>function() { return x + v } : () => string +>x + v : string +>x : string +>v : string (() => x + v); ->(() => x + v) : () => any ->() => x + v : () => any ->x + v : any ->x : any ->v : any +>(() => x + v) : () => string +>() => x + v : () => string +>x + v : string +>x : string +>v : string } use(v); >use(v) : any >use : (a: any) => any ->v : any +>v : string } function foo1(x) { @@ -438,32 +438,32 @@ function foo0_1_c(x) { >x : any for (const x in []) { ->x : any +>x : string >[] : undefined[] var v = x; ->v : any ->x : any +>v : string +>x : string (function() { return x + v }); ->(function() { return x + v }) : () => any ->function() { return x + v } : () => any ->x + v : any ->x : any ->v : any +>(function() { return x + v }) : () => string +>function() { return x + v } : () => string +>x + v : string +>x : string +>v : string (() => x + v); ->(() => x + v) : () => any ->() => x + v : () => any ->x + v : any ->x : any ->v : any +>(() => x + v) : () => string +>() => x + v : () => string +>x + v : string +>x : string +>v : string } use(v); >use(v) : any >use : (a: any) => any ->v : any +>v : string } function foo1_c(x) { diff --git a/tests/baselines/reference/capturedLetConstInLoop3_ES6.types b/tests/baselines/reference/capturedLetConstInLoop3_ES6.types index cc4b57ff9ea46..03377d913c967 100644 --- a/tests/baselines/reference/capturedLetConstInLoop3_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop3_ES6.types @@ -43,32 +43,32 @@ function foo0_1(x) { >x : any for (let x in []) { ->x : any +>x : string >[] : undefined[] var v = x; ->v : any ->x : any +>v : string +>x : string (function() { return x + v }); ->(function() { return x + v }) : () => any ->function() { return x + v } : () => any ->x + v : any ->x : any ->v : any +>(function() { return x + v }) : () => string +>function() { return x + v } : () => string +>x + v : string +>x : string +>v : string (() => x + v); ->(() => x + v) : () => any ->() => x + v : () => any ->x + v : any ->x : any ->v : any +>(() => x + v) : () => string +>() => x + v : () => string +>x + v : string +>x : string +>v : string } use(v); >use(v) : any >use : (a: any) => any ->v : any +>v : string } function foo1(x) { @@ -439,32 +439,32 @@ function foo0_1_c(x) { >x : any for (const x in []) { ->x : any +>x : string >[] : undefined[] var v = x; ->v : any ->x : any +>v : string +>x : string (function() { return x + v }); ->(function() { return x + v }) : () => any ->function() { return x + v } : () => any ->x + v : any ->x : any ->v : any +>(function() { return x + v }) : () => string +>function() { return x + v } : () => string +>x + v : string +>x : string +>v : string (() => x + v); ->(() => x + v) : () => any ->() => x + v : () => any ->x + v : any ->x : any ->v : any +>(() => x + v) : () => string +>() => x + v : () => string +>x + v : string +>x : string +>v : string } use(v); >use(v) : any >use : (a: any) => any ->v : any +>v : string } function foo1_c(x) { diff --git a/tests/baselines/reference/capturedLetConstInLoop4.types b/tests/baselines/reference/capturedLetConstInLoop4.types index f19e5d109b874..1bc928cefe447 100644 --- a/tests/baselines/reference/capturedLetConstInLoop4.types +++ b/tests/baselines/reference/capturedLetConstInLoop4.types @@ -2,20 +2,20 @@ //======let export function exportedFoo() { ->exportedFoo : () => any +>exportedFoo : () => string return v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8; ->v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 : any ->v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 + v7 : any ->v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 : any ->v0 + v00 + v1 + v2 + v3 + v4 + v5 : any ->v0 + v00 + v1 + v2 + v3 + v4 : any ->v0 + v00 + v1 + v2 + v3 : any ->v0 + v00 + v1 + v2 : any ->v0 + v00 + v1 : any ->v0 + v00 : any +>v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 : string +>v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 + v7 : string +>v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 : string +>v0 + v00 + v1 + v2 + v3 + v4 + v5 : string +>v0 + v00 + v1 + v2 + v3 + v4 : string +>v0 + v00 + v1 + v2 + v3 : string +>v0 + v00 + v1 + v2 : string +>v0 + v00 + v1 : string +>v0 + v00 : string >v0 : any ->v00 : any +>v00 : string >v1 : number >v2 : any >v3 : any @@ -48,24 +48,24 @@ for (let x of []) { } for (let x in []) { ->x : any +>x : string >[] : undefined[] var v00 = x; ->v00 : any ->x : any +>v00 : string +>x : string (function() { return x + v00}); ->(function() { return x + v00}) : () => any ->function() { return x + v00} : () => any ->x + v00 : any ->x : any ->v00 : any +>(function() { return x + v00}) : () => string +>function() { return x + v00} : () => string +>x + v00 : string +>x : string +>v00 : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string } for (let x = 0; x < 1; ++x) { @@ -302,20 +302,20 @@ for (let y = 0; y < 1; ++y) { //======const export function exportedFoo2() { ->exportedFoo2 : () => any +>exportedFoo2 : () => string return v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c + v7_c + v8_c; ->v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c + v7_c + v8_c : any ->v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c + v7_c : any ->v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c : any ->v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c : any ->v0_c + v00_c + v1_c + v2_c + v3_c + v4_c : any ->v0_c + v00_c + v1_c + v2_c + v3_c : any ->v0_c + v00_c + v1_c + v2_c : any ->v0_c + v00_c + v1_c : any ->v0_c + v00_c : any +>v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c + v7_c + v8_c : string +>v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c + v7_c : string +>v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c : string +>v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c : string +>v0_c + v00_c + v1_c + v2_c + v3_c + v4_c : string +>v0_c + v00_c + v1_c + v2_c + v3_c : string +>v0_c + v00_c + v1_c + v2_c : string +>v0_c + v00_c + v1_c : string +>v0_c + v00_c : string >v0_c : any ->v00_c : any +>v00_c : string >v1_c : number >v2_c : number >v3_c : number @@ -348,24 +348,24 @@ for (const x of []) { } for (const x in []) { ->x : any +>x : string >[] : undefined[] var v00_c = x; ->v00_c : any ->x : any +>v00_c : string +>x : string (function() { return x + v00}); ->(function() { return x + v00}) : () => any ->function() { return x + v00} : () => any ->x + v00 : any ->x : any ->v00 : any +>(function() { return x + v00}) : () => string +>function() { return x + v00} : () => string +>x + v00 : string +>x : string +>v00 : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string } for (const x = 0; x < 1;) { diff --git a/tests/baselines/reference/capturedLetConstInLoop4_ES6.types b/tests/baselines/reference/capturedLetConstInLoop4_ES6.types index fd5f6dadf62ad..cf44c7b69819e 100644 --- a/tests/baselines/reference/capturedLetConstInLoop4_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop4_ES6.types @@ -2,20 +2,20 @@ //======let export function exportedFoo() { ->exportedFoo : () => any +>exportedFoo : () => string return v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8; ->v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 : any ->v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 + v7 : any ->v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 : any ->v0 + v00 + v1 + v2 + v3 + v4 + v5 : any ->v0 + v00 + v1 + v2 + v3 + v4 : any ->v0 + v00 + v1 + v2 + v3 : any ->v0 + v00 + v1 + v2 : any ->v0 + v00 + v1 : any ->v0 + v00 : any +>v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 : string +>v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 + v7 : string +>v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 : string +>v0 + v00 + v1 + v2 + v3 + v4 + v5 : string +>v0 + v00 + v1 + v2 + v3 + v4 : string +>v0 + v00 + v1 + v2 + v3 : string +>v0 + v00 + v1 + v2 : string +>v0 + v00 + v1 : string +>v0 + v00 : string >v0 : any ->v00 : any +>v00 : string >v1 : number >v2 : any >v3 : any @@ -48,24 +48,24 @@ for (let x of []) { } for (let x in []) { ->x : any +>x : string >[] : undefined[] var v00 = x; ->v00 : any ->x : any +>v00 : string +>x : string (function() { return x + v00}); ->(function() { return x + v00}) : () => any ->function() { return x + v00} : () => any ->x + v00 : any ->x : any ->v00 : any +>(function() { return x + v00}) : () => string +>function() { return x + v00} : () => string +>x + v00 : string +>x : string +>v00 : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string } for (let x = 0; x < 1; ++x) { @@ -302,20 +302,20 @@ for (let y = 0; y < 1; ++y) { //======const export function exportedFoo2() { ->exportedFoo2 : () => any +>exportedFoo2 : () => string return v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c + v7_c + v8_c; ->v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c + v7_c + v8_c : any ->v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c + v7_c : any ->v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c : any ->v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c : any ->v0_c + v00_c + v1_c + v2_c + v3_c + v4_c : any ->v0_c + v00_c + v1_c + v2_c + v3_c : any ->v0_c + v00_c + v1_c + v2_c : any ->v0_c + v00_c + v1_c : any ->v0_c + v00_c : any +>v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c + v7_c + v8_c : string +>v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c + v7_c : string +>v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c : string +>v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c : string +>v0_c + v00_c + v1_c + v2_c + v3_c + v4_c : string +>v0_c + v00_c + v1_c + v2_c + v3_c : string +>v0_c + v00_c + v1_c + v2_c : string +>v0_c + v00_c + v1_c : string +>v0_c + v00_c : string >v0_c : any ->v00_c : any +>v00_c : string >v1_c : number >v2_c : number >v3_c : number @@ -348,24 +348,24 @@ for (const x of []) { } for (const x in []) { ->x : any +>x : string >[] : undefined[] var v00_c = x; ->v00_c : any ->x : any +>v00_c : string +>x : string (function() { return x + v00}); ->(function() { return x + v00}) : () => any ->function() { return x + v00} : () => any ->x + v00 : any ->x : any ->v00 : any +>(function() { return x + v00}) : () => string +>function() { return x + v00} : () => string +>x + v00 : string +>x : string +>v00 : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string } for (const x = 0; x < 1;) { diff --git a/tests/baselines/reference/capturedLetConstInLoop5.js b/tests/baselines/reference/capturedLetConstInLoop5.js index d7d177a19b9c2..b73484cb430b0 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5.js +++ b/tests/baselines/reference/capturedLetConstInLoop5.js @@ -20,7 +20,7 @@ function foo00(x) { var v = x; (function() { return x + v }); (() => x + v); - if (x == 1) { + if (x == "1") { return; } } @@ -159,7 +159,7 @@ function foo00_c(x) { var v = x; (function() { return x + v }); (() => x + v); - if (x == 1) { + if (x == "1") { return; } } @@ -303,7 +303,7 @@ function foo00(x) { v = x_2; (function () { return x_2 + v; }); (function () { return x_2 + v; }); - if (x_2 == 1) { + if (x_2 == "1") { return { value: void 0 }; } }; @@ -471,7 +471,7 @@ function foo00_c(x) { v = x_12; (function () { return x_12 + v; }); (function () { return x_12 + v; }); - if (x_12 == 1) { + if (x_12 == "1") { return { value: void 0 }; } }; diff --git a/tests/baselines/reference/capturedLetConstInLoop5.symbols b/tests/baselines/reference/capturedLetConstInLoop5.symbols index 2d514e8c88cf4..965379d3a1123 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5.symbols +++ b/tests/baselines/reference/capturedLetConstInLoop5.symbols @@ -54,7 +54,7 @@ function foo00(x) { >x : Symbol(x, Decl(capturedLetConstInLoop5.ts, 17, 12)) >v : Symbol(v, Decl(capturedLetConstInLoop5.ts, 18, 11)) - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop5.ts, 17, 12)) return; @@ -395,7 +395,7 @@ function foo00_c(x) { >x : Symbol(x, Decl(capturedLetConstInLoop5.ts, 156, 14)) >v : Symbol(v, Decl(capturedLetConstInLoop5.ts, 157, 11)) - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop5.ts, 156, 14)) return; diff --git a/tests/baselines/reference/capturedLetConstInLoop5.types b/tests/baselines/reference/capturedLetConstInLoop5.types index 3654ffe5820e2..b7b4b880dc4c1 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5.types +++ b/tests/baselines/reference/capturedLetConstInLoop5.types @@ -50,31 +50,31 @@ function foo00(x) { >x : any for (let x in []) { ->x : any +>x : string >[] : undefined[] var v = x; ->v : any ->x : any +>v : string +>x : string (function() { return x + v }); ->(function() { return x + v }) : () => any ->function() { return x + v } : () => any ->x + v : any ->x : any ->v : any +>(function() { return x + v }) : () => string +>function() { return x + v } : () => string +>x + v : string +>x : string +>v : string (() => x + v); ->(() => x + v) : () => any ->() => x + v : () => any ->x + v : any ->x : any ->v : any +>(() => x + v) : () => string +>() => x + v : () => string +>x + v : string +>x : string +>v : string - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string return; } @@ -83,7 +83,7 @@ function foo00(x) { use(v); >use(v) : any >use : (a: any) => any ->v : any +>v : string } function foo1(x) { @@ -525,31 +525,31 @@ function foo00_c(x) { >x : any for (const x in []) { ->x : any +>x : string >[] : undefined[] var v = x; ->v : any ->x : any +>v : string +>x : string (function() { return x + v }); ->(function() { return x + v }) : () => any ->function() { return x + v } : () => any ->x + v : any ->x : any ->v : any +>(function() { return x + v }) : () => string +>function() { return x + v } : () => string +>x + v : string +>x : string +>v : string (() => x + v); ->(() => x + v) : () => any ->() => x + v : () => any ->x + v : any ->x : any ->v : any +>(() => x + v) : () => string +>() => x + v : () => string +>x + v : string +>x : string +>v : string - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string return; } @@ -558,7 +558,7 @@ function foo00_c(x) { use(v); >use(v) : any >use : (a: any) => any ->v : any +>v : string } function foo1_c(x) { diff --git a/tests/baselines/reference/capturedLetConstInLoop5_ES6.js b/tests/baselines/reference/capturedLetConstInLoop5_ES6.js index e5996bb305366..0f0624b8a8b6d 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5_ES6.js +++ b/tests/baselines/reference/capturedLetConstInLoop5_ES6.js @@ -21,7 +21,7 @@ function foo00(x) { var v = x; (function() { return x + v }); (() => x + v); - if (x == 1) { + if (x == "1") { return; } } @@ -160,7 +160,7 @@ function foo00_c(x) { var v = x; (function() { return x + v }); (() => x + v); - if (x == 1) { + if (x == "1") { return; } } @@ -298,7 +298,7 @@ function foo00(x) { var v = x; (function () { return x + v; }); (() => x + v); - if (x == 1) { + if (x == "1") { return; } } @@ -416,7 +416,7 @@ function foo00_c(x) { var v = x; (function () { return x + v; }); (() => x + v); - if (x == 1) { + if (x == "1") { return; } } diff --git a/tests/baselines/reference/capturedLetConstInLoop5_ES6.symbols b/tests/baselines/reference/capturedLetConstInLoop5_ES6.symbols index b3d338ad60e0c..5b40cb4459958 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5_ES6.symbols +++ b/tests/baselines/reference/capturedLetConstInLoop5_ES6.symbols @@ -55,7 +55,7 @@ function foo00(x) { >x : Symbol(x, Decl(capturedLetConstInLoop5_ES6.ts, 18, 12)) >v : Symbol(v, Decl(capturedLetConstInLoop5_ES6.ts, 19, 11)) - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop5_ES6.ts, 18, 12)) return; @@ -396,7 +396,7 @@ function foo00_c(x) { >x : Symbol(x, Decl(capturedLetConstInLoop5_ES6.ts, 157, 14)) >v : Symbol(v, Decl(capturedLetConstInLoop5_ES6.ts, 158, 11)) - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop5_ES6.ts, 157, 14)) return; diff --git a/tests/baselines/reference/capturedLetConstInLoop5_ES6.types b/tests/baselines/reference/capturedLetConstInLoop5_ES6.types index 8db8ae25e9b86..855bbfc63086a 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop5_ES6.types @@ -51,31 +51,31 @@ function foo00(x) { >x : any for (let x in []) { ->x : any +>x : string >[] : undefined[] var v = x; ->v : any ->x : any +>v : string +>x : string (function() { return x + v }); ->(function() { return x + v }) : () => any ->function() { return x + v } : () => any ->x + v : any ->x : any ->v : any +>(function() { return x + v }) : () => string +>function() { return x + v } : () => string +>x + v : string +>x : string +>v : string (() => x + v); ->(() => x + v) : () => any ->() => x + v : () => any ->x + v : any ->x : any ->v : any +>(() => x + v) : () => string +>() => x + v : () => string +>x + v : string +>x : string +>v : string - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string return; } @@ -84,7 +84,7 @@ function foo00(x) { use(v); >use(v) : any >use : (a: any) => any ->v : any +>v : string } function foo1(x) { @@ -526,31 +526,31 @@ function foo00_c(x) { >x : any for (const x in []) { ->x : any +>x : string >[] : undefined[] var v = x; ->v : any ->x : any +>v : string +>x : string (function() { return x + v }); ->(function() { return x + v }) : () => any ->function() { return x + v } : () => any ->x + v : any ->x : any ->v : any +>(function() { return x + v }) : () => string +>function() { return x + v } : () => string +>x + v : string +>x : string +>v : string (() => x + v); ->(() => x + v) : () => any ->() => x + v : () => any ->x + v : any ->x : any ->v : any +>(() => x + v) : () => string +>() => x + v : () => string +>x + v : string +>x : string +>v : string - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string return; } @@ -559,7 +559,7 @@ function foo00_c(x) { use(v); >use(v) : any >use : (a: any) => any ->v : any +>v : string } function foo1_c(x) { diff --git a/tests/baselines/reference/capturedLetConstInLoop6.js b/tests/baselines/reference/capturedLetConstInLoop6.js index 187d9f10ad30e..ca3b634ef18de 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6.js +++ b/tests/baselines/reference/capturedLetConstInLoop6.js @@ -14,10 +14,10 @@ for (let x of []) { for (let x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 2) { + if (x == "2") { continue; } } @@ -133,10 +133,10 @@ for (const x of []) { for (const x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 2) { + if (x == "2") { continue; } } @@ -259,10 +259,10 @@ for (var _i = 0, _a = []; _i < _a.length; _i++) { var _loop_2 = function(x) { (function () { return x; }); (function () { return x; }); - if (x == 1) { + if (x == "1") { return "break"; } - if (x == 2) { + if (x == "2") { return "continue"; } }; @@ -417,10 +417,10 @@ for (var _b = 0, _c = []; _b < _c.length; _b++) { var _loop_12 = function(x) { (function () { return x; }); (function () { return x; }); - if (x == 1) { + if (x == "1") { return "break"; } - if (x == 2) { + if (x == "2") { return "continue"; } }; diff --git a/tests/baselines/reference/capturedLetConstInLoop6.symbols b/tests/baselines/reference/capturedLetConstInLoop6.symbols index 8d8e6d6ce5965..872bc3a4727b1 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6.symbols +++ b/tests/baselines/reference/capturedLetConstInLoop6.symbols @@ -30,12 +30,12 @@ for (let x in []) { (() => x); >x : Symbol(x, Decl(capturedLetConstInLoop6.ts, 12, 8)) - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop6.ts, 12, 8)) break; } - if (x == 2) { + if (x == "2") { >x : Symbol(x, Decl(capturedLetConstInLoop6.ts, 12, 8)) continue; @@ -272,12 +272,12 @@ for (const x in []) { (() => x); >x : Symbol(x, Decl(capturedLetConstInLoop6.ts, 131, 10)) - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop6.ts, 131, 10)) break; } - if (x == 2) { + if (x == "2") { >x : Symbol(x, Decl(capturedLetConstInLoop6.ts, 131, 10)) continue; diff --git a/tests/baselines/reference/capturedLetConstInLoop6.types b/tests/baselines/reference/capturedLetConstInLoop6.types index 6c31bdef31b98..f2b1103305fb8 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6.types +++ b/tests/baselines/reference/capturedLetConstInLoop6.types @@ -31,30 +31,30 @@ for (let x of []) { } for (let x in []) { ->x : any +>x : string >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => string +>function() { return x} : () => string +>x : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string break; } - if (x == 2) { ->x == 2 : boolean ->x : any ->2 : number + if (x == "2") { +>x == "2" : boolean +>x : string +>"2" : string continue; } @@ -396,30 +396,30 @@ for (const x of []) { } for (const x in []) { ->x : any +>x : string >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => string +>function() { return x} : () => string +>x : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string break; } - if (x == 2) { ->x == 2 : boolean ->x : any ->2 : number + if (x == "2") { +>x == "2" : boolean +>x : string +>"2" : string continue; } diff --git a/tests/baselines/reference/capturedLetConstInLoop6_ES6.js b/tests/baselines/reference/capturedLetConstInLoop6_ES6.js index 924f55b69153f..33d64e889276a 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6_ES6.js +++ b/tests/baselines/reference/capturedLetConstInLoop6_ES6.js @@ -14,10 +14,10 @@ for (let x of []) { for (let x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 2) { + if (x == "2") { continue; } } @@ -133,10 +133,10 @@ for (const x of []) { for (const x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 2) { + if (x == "2") { continue; } } @@ -253,10 +253,10 @@ for (let x of []) { for (let x in []) { (function () { return x; }); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 2) { + if (x == "2") { continue; } } @@ -360,10 +360,10 @@ for (const x of []) { for (const x in []) { (function () { return x; }); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 2) { + if (x == "2") { continue; } } diff --git a/tests/baselines/reference/capturedLetConstInLoop6_ES6.symbols b/tests/baselines/reference/capturedLetConstInLoop6_ES6.symbols index acd557e471486..63cb26c4300ad 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6_ES6.symbols +++ b/tests/baselines/reference/capturedLetConstInLoop6_ES6.symbols @@ -30,12 +30,12 @@ for (let x in []) { (() => x); >x : Symbol(x, Decl(capturedLetConstInLoop6_ES6.ts, 12, 8)) - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop6_ES6.ts, 12, 8)) break; } - if (x == 2) { + if (x == "2") { >x : Symbol(x, Decl(capturedLetConstInLoop6_ES6.ts, 12, 8)) continue; @@ -272,12 +272,12 @@ for (const x in []) { (() => x); >x : Symbol(x, Decl(capturedLetConstInLoop6_ES6.ts, 131, 10)) - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop6_ES6.ts, 131, 10)) break; } - if (x == 2) { + if (x == "2") { >x : Symbol(x, Decl(capturedLetConstInLoop6_ES6.ts, 131, 10)) continue; diff --git a/tests/baselines/reference/capturedLetConstInLoop6_ES6.types b/tests/baselines/reference/capturedLetConstInLoop6_ES6.types index 87f21709120c4..cfd55a63aaab2 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop6_ES6.types @@ -31,30 +31,30 @@ for (let x of []) { } for (let x in []) { ->x : any +>x : string >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => string +>function() { return x} : () => string +>x : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string break; } - if (x == 2) { ->x == 2 : boolean ->x : any ->2 : number + if (x == "2") { +>x == "2" : boolean +>x : string +>"2" : string continue; } @@ -396,30 +396,30 @@ for (const x of []) { } for (const x in []) { ->x : any +>x : string >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => string +>function() { return x} : () => string +>x : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string break; } - if (x == 2) { ->x == 2 : boolean ->x : any ->2 : number + if (x == "2") { +>x == "2" : boolean +>x : string +>"2" : string continue; } diff --git a/tests/baselines/reference/capturedLetConstInLoop7.js b/tests/baselines/reference/capturedLetConstInLoop7.js index ce6769d2b1afb..6ec4ec1df447d 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7.js +++ b/tests/baselines/reference/capturedLetConstInLoop7.js @@ -22,16 +22,16 @@ l00: for (let x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 1) { + if (x == "1") { break l00; } - if (x == 2) { + if (x == "2") { continue; } - if (x == 2) { + if (x == "2") { continue l00; } } @@ -210,16 +210,16 @@ l00_c: for (const x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 1) { + if (x == "1") { break l00_c; } - if (x == 2) { + if (x == "2") { continue; } - if (x == 2) { + if (x == "2") { continue l00_c; } } @@ -406,16 +406,16 @@ l0: for (var _i = 0, _a = []; _i < _a.length; _i++) { var _loop_2 = function(x) { (function () { return x; }); (function () { return x; }); - if (x == 1) { + if (x == "1") { return "break"; } - if (x == 1) { + if (x == "1") { return "break-l00"; } - if (x == 2) { + if (x == "2") { return "continue"; } - if (x == 2) { + if (x == "2") { return "continue-l00"; } }; @@ -664,16 +664,16 @@ l0_c: for (var _b = 0, _c = []; _b < _c.length; _b++) { var _loop_12 = function(x) { (function () { return x; }); (function () { return x; }); - if (x == 1) { + if (x == "1") { return "break"; } - if (x == 1) { + if (x == "1") { return "break-l00_c"; } - if (x == 2) { + if (x == "2") { return "continue"; } - if (x == 2) { + if (x == "2") { return "continue-l00_c"; } }; diff --git a/tests/baselines/reference/capturedLetConstInLoop7.symbols b/tests/baselines/reference/capturedLetConstInLoop7.symbols index 2aa5ec2cd383c..0f4395a6d6873 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7.symbols +++ b/tests/baselines/reference/capturedLetConstInLoop7.symbols @@ -42,22 +42,22 @@ for (let x in []) { (() => x); >x : Symbol(x, Decl(capturedLetConstInLoop7.ts, 20, 8)) - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop7.ts, 20, 8)) break; } - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop7.ts, 20, 8)) break l00; } - if (x == 2) { + if (x == "2") { >x : Symbol(x, Decl(capturedLetConstInLoop7.ts, 20, 8)) continue; } - if (x == 2) { + if (x == "2") { >x : Symbol(x, Decl(capturedLetConstInLoop7.ts, 20, 8)) continue l00; @@ -393,22 +393,22 @@ for (const x in []) { (() => x); >x : Symbol(x, Decl(capturedLetConstInLoop7.ts, 208, 10)) - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop7.ts, 208, 10)) break; } - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop7.ts, 208, 10)) break l00_c; } - if (x == 2) { + if (x == "2") { >x : Symbol(x, Decl(capturedLetConstInLoop7.ts, 208, 10)) continue; } - if (x == 2) { + if (x == "2") { >x : Symbol(x, Decl(capturedLetConstInLoop7.ts, 208, 10)) continue l00_c; diff --git a/tests/baselines/reference/capturedLetConstInLoop7.types b/tests/baselines/reference/capturedLetConstInLoop7.types index 280985eae0f9e..29ea34e39a16b 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7.types +++ b/tests/baselines/reference/capturedLetConstInLoop7.types @@ -53,45 +53,45 @@ l00: >l00 : any for (let x in []) { ->x : any +>x : string >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => string +>function() { return x} : () => string +>x : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string break; } - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string break l00; >l00 : any } - if (x == 2) { ->x == 2 : boolean ->x : any ->2 : number + if (x == "2") { +>x == "2" : boolean +>x : string +>"2" : string continue; } - if (x == 2) { ->x == 2 : boolean ->x : any ->2 : number + if (x == "2") { +>x == "2" : boolean +>x : string +>"2" : string continue l00; >l00 : any @@ -607,45 +607,45 @@ l00_c: >l00_c : any for (const x in []) { ->x : any +>x : string >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => string +>function() { return x} : () => string +>x : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string break; } - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string break l00_c; >l00_c : any } - if (x == 2) { ->x == 2 : boolean ->x : any ->2 : number + if (x == "2") { +>x == "2" : boolean +>x : string +>"2" : string continue; } - if (x == 2) { ->x == 2 : boolean ->x : any ->2 : number + if (x == "2") { +>x == "2" : boolean +>x : string +>"2" : string continue l00_c; >l00_c : any diff --git a/tests/baselines/reference/capturedLetConstInLoop7_ES6.js b/tests/baselines/reference/capturedLetConstInLoop7_ES6.js index 4a2db64008121..13c69a883921f 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7_ES6.js +++ b/tests/baselines/reference/capturedLetConstInLoop7_ES6.js @@ -22,16 +22,16 @@ l00: for (let x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 1) { + if (x == "1") { break l00; } - if (x == 2) { + if (x == "2") { continue; } - if (x == 2) { + if (x == "2") { continue l00; } } @@ -210,16 +210,16 @@ l00_c: for (const x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 1) { + if (x == "1") { break l00_c; } - if (x == 2) { + if (x == "2") { continue; } - if (x == 2) { + if (x == "2") { continue l00_c; } } @@ -396,16 +396,16 @@ l0: for (let x of []) { l00: for (let x in []) { (function () { return x; }); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 1) { + if (x == "1") { break l00; } - if (x == 2) { + if (x == "2") { continue; } - if (x == 2) { + if (x == "2") { continue l00; } } @@ -563,16 +563,16 @@ l0_c: for (const x of []) { l00_c: for (const x in []) { (function () { return x; }); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 1) { + if (x == "1") { break l00_c; } - if (x == 2) { + if (x == "2") { continue; } - if (x == 2) { + if (x == "2") { continue l00_c; } } diff --git a/tests/baselines/reference/capturedLetConstInLoop7_ES6.symbols b/tests/baselines/reference/capturedLetConstInLoop7_ES6.symbols index 51131f421bae9..a817377834ba8 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7_ES6.symbols +++ b/tests/baselines/reference/capturedLetConstInLoop7_ES6.symbols @@ -42,22 +42,22 @@ for (let x in []) { (() => x); >x : Symbol(x, Decl(capturedLetConstInLoop7_ES6.ts, 20, 8)) - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop7_ES6.ts, 20, 8)) break; } - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop7_ES6.ts, 20, 8)) break l00; } - if (x == 2) { + if (x == "2") { >x : Symbol(x, Decl(capturedLetConstInLoop7_ES6.ts, 20, 8)) continue; } - if (x == 2) { + if (x == "2") { >x : Symbol(x, Decl(capturedLetConstInLoop7_ES6.ts, 20, 8)) continue l00; @@ -393,22 +393,22 @@ for (const x in []) { (() => x); >x : Symbol(x, Decl(capturedLetConstInLoop7_ES6.ts, 208, 10)) - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop7_ES6.ts, 208, 10)) break; } - if (x == 1) { + if (x == "1") { >x : Symbol(x, Decl(capturedLetConstInLoop7_ES6.ts, 208, 10)) break l00_c; } - if (x == 2) { + if (x == "2") { >x : Symbol(x, Decl(capturedLetConstInLoop7_ES6.ts, 208, 10)) continue; } - if (x == 2) { + if (x == "2") { >x : Symbol(x, Decl(capturedLetConstInLoop7_ES6.ts, 208, 10)) continue l00_c; diff --git a/tests/baselines/reference/capturedLetConstInLoop7_ES6.types b/tests/baselines/reference/capturedLetConstInLoop7_ES6.types index 56573fb492737..c72afb4194200 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop7_ES6.types @@ -53,45 +53,45 @@ l00: >l00 : any for (let x in []) { ->x : any +>x : string >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => string +>function() { return x} : () => string +>x : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string break; } - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string break l00; >l00 : any } - if (x == 2) { ->x == 2 : boolean ->x : any ->2 : number + if (x == "2") { +>x == "2" : boolean +>x : string +>"2" : string continue; } - if (x == 2) { ->x == 2 : boolean ->x : any ->2 : number + if (x == "2") { +>x == "2" : boolean +>x : string +>"2" : string continue l00; >l00 : any @@ -607,45 +607,45 @@ l00_c: >l00_c : any for (const x in []) { ->x : any +>x : string >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => string +>function() { return x} : () => string +>x : string (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => string +>() => x : () => string +>x : string - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string break; } - if (x == 1) { ->x == 1 : boolean ->x : any ->1 : number + if (x == "1") { +>x == "1" : boolean +>x : string +>"1" : string break l00_c; >l00_c : any } - if (x == 2) { ->x == 2 : boolean ->x : any ->2 : number + if (x == "2") { +>x == "2" : boolean +>x : string +>"2" : string continue; } - if (x == 2) { ->x == 2 : boolean ->x : any ->2 : number + if (x == "2") { +>x == "2" : boolean +>x : string +>"2" : string continue l00_c; >l00_c : any diff --git a/tests/baselines/reference/downlevelLetConst17.types b/tests/baselines/reference/downlevelLetConst17.types index 824abcc76be52..4f539835ada42 100644 --- a/tests/baselines/reference/downlevelLetConst17.types +++ b/tests/baselines/reference/downlevelLetConst17.types @@ -139,23 +139,23 @@ do { >true : boolean for (let x in []) { ->x : any +>x : string >[] : undefined[] use(x); >use(x) : any >use : (a: any) => any ->x : any +>x : string } for (const x in []) { ->x : any +>x : string >[] : undefined[] use(x); >use(x) : any >use : (a: any) => any ->x : any +>x : string } for (const x of []) { diff --git a/tests/baselines/reference/duplicateLocalVariable1.errors.txt b/tests/baselines/reference/duplicateLocalVariable1.errors.txt index 0a49c71e29bd0..90c5974cd2b6a 100644 --- a/tests/baselines/reference/duplicateLocalVariable1.errors.txt +++ b/tests/baselines/reference/duplicateLocalVariable1.errors.txt @@ -2,10 +2,12 @@ tests/cases/compiler/duplicateLocalVariable1.ts(2,4): error TS1005: ';' expected tests/cases/compiler/duplicateLocalVariable1.ts(2,11): error TS1146: Declaration expected. tests/cases/compiler/duplicateLocalVariable1.ts(2,13): error TS2304: Cannot find name 'commonjs'. tests/cases/compiler/duplicateLocalVariable1.ts(12,14): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file. -tests/cases/compiler/duplicateLocalVariable1.ts(187,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'any', but here has type 'number'. +tests/cases/compiler/duplicateLocalVariable1.ts(187,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'string', but here has type 'number'. +tests/cases/compiler/duplicateLocalVariable1.ts(187,29): error TS2365: Operator '<' cannot be applied to types 'string' and 'number'. +tests/cases/compiler/duplicateLocalVariable1.ts(187,37): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -==== tests/cases/compiler/duplicateLocalVariable1.ts (5 errors) ==== +==== tests/cases/compiler/duplicateLocalVariable1.ts (7 errors) ==== / /@module: commonjs ~ @@ -202,7 +204,11 @@ tests/cases/compiler/duplicateLocalVariable1.ts(187,22): error TS2403: Subsequen var bytes = []; for (var i = 0; i < 14; i++) { ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'any', but here has type 'number'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'string', but here has type 'number'. + ~~~~~~ +!!! error TS2365: Operator '<' cannot be applied to types 'string' and 'number'. + ~ +!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. bytes.push(fb.readByte()); } var expected = [0xEF, 0xBB, 0xBF, 0x54, 0xC3, 0xA8, 0xE1, 0xB4, 0xA3, 0xE2, 0x80, 0xA0, 0x0D, 0x0A]; diff --git a/tests/baselines/reference/duplicateLocalVariable2.errors.txt b/tests/baselines/reference/duplicateLocalVariable2.errors.txt index 0fbe0018bf881..5e89cc422cce9 100644 --- a/tests/baselines/reference/duplicateLocalVariable2.errors.txt +++ b/tests/baselines/reference/duplicateLocalVariable2.errors.txt @@ -1,7 +1,9 @@ -tests/cases/compiler/duplicateLocalVariable2.ts(27,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'any', but here has type 'number'. +tests/cases/compiler/duplicateLocalVariable2.ts(27,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'string', but here has type 'number'. +tests/cases/compiler/duplicateLocalVariable2.ts(27,29): error TS2365: Operator '<' cannot be applied to types 'string' and 'number'. +tests/cases/compiler/duplicateLocalVariable2.ts(27,37): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -==== tests/cases/compiler/duplicateLocalVariable2.ts (1 errors) ==== +==== tests/cases/compiler/duplicateLocalVariable2.ts (3 errors) ==== export class TestCase { constructor (public name: string, public test: ()=>boolean, public errorMessageRegEx?: string) { } @@ -30,7 +32,11 @@ tests/cases/compiler/duplicateLocalVariable2.ts(27,22): error TS2403: Subsequent var bytes = []; for (var i = 0; i < 14; i++) { ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'any', but here has type 'number'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'string', but here has type 'number'. + ~~~~~~ +!!! error TS2365: Operator '<' cannot be applied to types 'string' and 'number'. + ~ +!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. bytes.push(fb.readByte()); } var expected = [0xEF]; diff --git a/tests/baselines/reference/for-inStatementsArray.js b/tests/baselines/reference/for-inStatementsArray.js new file mode 100644 index 0000000000000..e3d331e2d8c2a --- /dev/null +++ b/tests/baselines/reference/for-inStatementsArray.js @@ -0,0 +1,76 @@ +//// [for-inStatementsArray.ts] +let a: Date[]; +let b: boolean[]; + +for (let x in a) { + let a1 = a[x]; + let a2 = a[(x)]; + let a3 = a[+x]; + let b1 = b[x]; + let b2 = b[(x)]; + let b3 = b[+x]; +} + +for (let x in a) { + for (let y in a) { + for (let z in a) { + let a1 = a[x]; + let a2 = a[y]; + let a3 = a[z]; + } + } +} + +let i: string; +let j: string; +for (i in a) { + for (j in b) { + let a1 = a[i]; + let a2 = a[j]; + } +} + +var s: string; +for (var s in a) { + let a1 = a[s]; +} +for (s in a) { + let a1 = a[s]; +} + + +//// [for-inStatementsArray.js] +var a; +var b; +for (var x in a) { + var a1 = a[x]; + var a2 = a[(x)]; + var a3 = a[+x]; + var b1 = b[x]; + var b2 = b[(x)]; + var b3 = b[+x]; +} +for (var x in a) { + for (var y in a) { + for (var z in a) { + var a1 = a[x]; + var a2 = a[y]; + var a3 = a[z]; + } + } +} +var i; +var j; +for (i in a) { + for (j in b) { + var a1 = a[i]; + var a2 = a[j]; + } +} +var s; +for (var s in a) { + var a1 = a[s]; +} +for (s in a) { + var a1 = a[s]; +} diff --git a/tests/baselines/reference/for-inStatementsArray.symbols b/tests/baselines/reference/for-inStatementsArray.symbols new file mode 100644 index 0000000000000..5b6ea9385cd38 --- /dev/null +++ b/tests/baselines/reference/for-inStatementsArray.symbols @@ -0,0 +1,121 @@ +=== tests/cases/conformance/statements/for-inStatements/for-inStatementsArray.ts === +let a: Date[]; +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) +>Date : Symbol(Date, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +let b: boolean[]; +>b : Symbol(b, Decl(for-inStatementsArray.ts, 1, 3)) + +for (let x in a) { +>x : Symbol(x, Decl(for-inStatementsArray.ts, 3, 8)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) + + let a1 = a[x]; +>a1 : Symbol(a1, Decl(for-inStatementsArray.ts, 4, 7)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) +>x : Symbol(x, Decl(for-inStatementsArray.ts, 3, 8)) + + let a2 = a[(x)]; +>a2 : Symbol(a2, Decl(for-inStatementsArray.ts, 5, 7)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) +>x : Symbol(x, Decl(for-inStatementsArray.ts, 3, 8)) + + let a3 = a[+x]; +>a3 : Symbol(a3, Decl(for-inStatementsArray.ts, 6, 7)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) +>x : Symbol(x, Decl(for-inStatementsArray.ts, 3, 8)) + + let b1 = b[x]; +>b1 : Symbol(b1, Decl(for-inStatementsArray.ts, 7, 7)) +>b : Symbol(b, Decl(for-inStatementsArray.ts, 1, 3)) +>x : Symbol(x, Decl(for-inStatementsArray.ts, 3, 8)) + + let b2 = b[(x)]; +>b2 : Symbol(b2, Decl(for-inStatementsArray.ts, 8, 7)) +>b : Symbol(b, Decl(for-inStatementsArray.ts, 1, 3)) +>x : Symbol(x, Decl(for-inStatementsArray.ts, 3, 8)) + + let b3 = b[+x]; +>b3 : Symbol(b3, Decl(for-inStatementsArray.ts, 9, 7)) +>b : Symbol(b, Decl(for-inStatementsArray.ts, 1, 3)) +>x : Symbol(x, Decl(for-inStatementsArray.ts, 3, 8)) +} + +for (let x in a) { +>x : Symbol(x, Decl(for-inStatementsArray.ts, 12, 8)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) + + for (let y in a) { +>y : Symbol(y, Decl(for-inStatementsArray.ts, 13, 12)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) + + for (let z in a) { +>z : Symbol(z, Decl(for-inStatementsArray.ts, 14, 16)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) + + let a1 = a[x]; +>a1 : Symbol(a1, Decl(for-inStatementsArray.ts, 15, 15)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) +>x : Symbol(x, Decl(for-inStatementsArray.ts, 12, 8)) + + let a2 = a[y]; +>a2 : Symbol(a2, Decl(for-inStatementsArray.ts, 16, 15)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) +>y : Symbol(y, Decl(for-inStatementsArray.ts, 13, 12)) + + let a3 = a[z]; +>a3 : Symbol(a3, Decl(for-inStatementsArray.ts, 17, 15)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) +>z : Symbol(z, Decl(for-inStatementsArray.ts, 14, 16)) + } + } +} + +let i: string; +>i : Symbol(i, Decl(for-inStatementsArray.ts, 22, 3)) + +let j: string; +>j : Symbol(j, Decl(for-inStatementsArray.ts, 23, 3)) + +for (i in a) { +>i : Symbol(i, Decl(for-inStatementsArray.ts, 22, 3)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) + + for (j in b) { +>j : Symbol(j, Decl(for-inStatementsArray.ts, 23, 3)) +>b : Symbol(b, Decl(for-inStatementsArray.ts, 1, 3)) + + let a1 = a[i]; +>a1 : Symbol(a1, Decl(for-inStatementsArray.ts, 26, 11)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) +>i : Symbol(i, Decl(for-inStatementsArray.ts, 22, 3)) + + let a2 = a[j]; +>a2 : Symbol(a2, Decl(for-inStatementsArray.ts, 27, 11)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) +>j : Symbol(j, Decl(for-inStatementsArray.ts, 23, 3)) + } +} + +var s: string; +>s : Symbol(s, Decl(for-inStatementsArray.ts, 31, 3), Decl(for-inStatementsArray.ts, 32, 8)) + +for (var s in a) { +>s : Symbol(s, Decl(for-inStatementsArray.ts, 31, 3), Decl(for-inStatementsArray.ts, 32, 8)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) + + let a1 = a[s]; +>a1 : Symbol(a1, Decl(for-inStatementsArray.ts, 33, 7)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) +>s : Symbol(s, Decl(for-inStatementsArray.ts, 31, 3), Decl(for-inStatementsArray.ts, 32, 8)) +} +for (s in a) { +>s : Symbol(s, Decl(for-inStatementsArray.ts, 31, 3), Decl(for-inStatementsArray.ts, 32, 8)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) + + let a1 = a[s]; +>a1 : Symbol(a1, Decl(for-inStatementsArray.ts, 36, 7)) +>a : Symbol(a, Decl(for-inStatementsArray.ts, 0, 3)) +>s : Symbol(s, Decl(for-inStatementsArray.ts, 31, 3), Decl(for-inStatementsArray.ts, 32, 8)) +} + diff --git a/tests/baselines/reference/for-inStatementsArray.types b/tests/baselines/reference/for-inStatementsArray.types new file mode 100644 index 0000000000000..048b2819ff7fd --- /dev/null +++ b/tests/baselines/reference/for-inStatementsArray.types @@ -0,0 +1,138 @@ +=== tests/cases/conformance/statements/for-inStatements/for-inStatementsArray.ts === +let a: Date[]; +>a : Date[] +>Date : Date + +let b: boolean[]; +>b : boolean[] + +for (let x in a) { +>x : string +>a : Date[] + + let a1 = a[x]; +>a1 : Date +>a[x] : Date +>a : Date[] +>x : string + + let a2 = a[(x)]; +>a2 : Date +>a[(x)] : Date +>a : Date[] +>(x) : string +>x : string + + let a3 = a[+x]; +>a3 : Date +>a[+x] : Date +>a : Date[] +>+x : number +>x : string + + let b1 = b[x]; +>b1 : boolean +>b[x] : boolean +>b : boolean[] +>x : string + + let b2 = b[(x)]; +>b2 : boolean +>b[(x)] : boolean +>b : boolean[] +>(x) : string +>x : string + + let b3 = b[+x]; +>b3 : boolean +>b[+x] : boolean +>b : boolean[] +>+x : number +>x : string +} + +for (let x in a) { +>x : string +>a : Date[] + + for (let y in a) { +>y : string +>a : Date[] + + for (let z in a) { +>z : string +>a : Date[] + + let a1 = a[x]; +>a1 : Date +>a[x] : Date +>a : Date[] +>x : string + + let a2 = a[y]; +>a2 : Date +>a[y] : Date +>a : Date[] +>y : string + + let a3 = a[z]; +>a3 : Date +>a[z] : Date +>a : Date[] +>z : string + } + } +} + +let i: string; +>i : string + +let j: string; +>j : string + +for (i in a) { +>i : string +>a : Date[] + + for (j in b) { +>j : string +>b : boolean[] + + let a1 = a[i]; +>a1 : Date +>a[i] : Date +>a : Date[] +>i : string + + let a2 = a[j]; +>a2 : Date +>a[j] : Date +>a : Date[] +>j : string + } +} + +var s: string; +>s : string + +for (var s in a) { +>s : string +>a : Date[] + + let a1 = a[s]; +>a1 : Date +>a[s] : Date +>a : Date[] +>s : string +} +for (s in a) { +>s : string +>a : Date[] + + let a1 = a[s]; +>a1 : Date +>a[s] : Date +>a : Date[] +>s : string +} + diff --git a/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt b/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt new file mode 100644 index 0000000000000..6886d992bb2e5 --- /dev/null +++ b/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt @@ -0,0 +1,40 @@ +tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(5,14): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. +tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(6,16): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(7,9): error TS2365: Operator '===' cannot be applied to types 'string' and 'number'. +tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(9,16): error TS2339: Property 'unknownProperty' does not exist on type 'string'. +tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(13,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'number', but here has type 'string'. +tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts(17,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'j' must be of type 'any', but here has type 'string'. + + +==== tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts (6 errors) ==== + + let a: Date[]; + + for (let x in a) { + let a1 = a[x + 1]; + ~~~~~~~~ +!!! error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. + let a2 = a[x - 1]; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + if (x === 1) { + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'string' and 'number'. + } + let a3 = x.unknownProperty; + ~~~~~~~~~~~~~~~ +!!! error TS2339: Property 'unknownProperty' does not exist on type 'string'. + } + + var i: number; + for (var i in a ) { + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'number', but here has type 'string'. + } + + var j: any; + for (var j in a ) { + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'j' must be of type 'any', but here has type 'string'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/for-inStatementsArrayErrors.js b/tests/baselines/reference/for-inStatementsArrayErrors.js new file mode 100644 index 0000000000000..981a840695ce0 --- /dev/null +++ b/tests/baselines/reference/for-inStatementsArrayErrors.js @@ -0,0 +1,36 @@ +//// [for-inStatementsArrayErrors.ts] + +let a: Date[]; + +for (let x in a) { + let a1 = a[x + 1]; + let a2 = a[x - 1]; + if (x === 1) { + } + let a3 = x.unknownProperty; +} + +var i: number; +for (var i in a ) { +} + +var j: any; +for (var j in a ) { +} + + +//// [for-inStatementsArrayErrors.js] +var a; +for (var x in a) { + var a1 = a[x + 1]; + var a2 = a[x - 1]; + if (x === 1) { + } + var a3 = x.unknownProperty; +} +var i; +for (var i in a) { +} +var j; +for (var j in a) { +} diff --git a/tests/baselines/reference/for-inStatementsDestructuring.errors.txt b/tests/baselines/reference/for-inStatementsDestructuring.errors.txt index e540b182cf5e7..e54f2c93272a3 100644 --- a/tests/baselines/reference/for-inStatementsDestructuring.errors.txt +++ b/tests/baselines/reference/for-inStatementsDestructuring.errors.txt @@ -1,7 +1,10 @@ +tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring.ts(1,10): error TS2461: Type 'string' is not an array type. tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring.ts(1,10): error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. -==== tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring.ts (1 errors) ==== +==== tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring.ts (2 errors) ==== for (var [a, b] in []) {} ~~~~~~ +!!! error TS2461: Type 'string' is not an array type. + ~~~~~~ !!! error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. \ No newline at end of file diff --git a/tests/baselines/reference/for-inStatementsDestructuring2.errors.txt b/tests/baselines/reference/for-inStatementsDestructuring2.errors.txt index 56d2436d4c78f..7589610a64e35 100644 --- a/tests/baselines/reference/for-inStatementsDestructuring2.errors.txt +++ b/tests/baselines/reference/for-inStatementsDestructuring2.errors.txt @@ -1,7 +1,13 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts(1,10): error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. +tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts(1,11): error TS2459: Type 'string' has no property 'a' and no string index signature. +tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts(1,14): error TS2459: Type 'string' has no property 'b' and no string index signature. -==== tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts (1 errors) ==== +==== tests/cases/conformance/statements/for-inStatements/for-inStatementsDestructuring2.ts (3 errors) ==== for (var {a, b} in []) {} ~~~~~~ -!!! error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. \ No newline at end of file +!!! error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. + ~ +!!! error TS2459: Type 'string' has no property 'a' and no string index signature. + ~ +!!! error TS2459: Type 'string' has no property 'b' and no string index signature. \ No newline at end of file diff --git a/tests/baselines/reference/for-inStatementsInvalid.errors.txt b/tests/baselines/reference/for-inStatementsInvalid.errors.txt index 67e536a3069f7..00ab58ab94da1 100644 --- a/tests/baselines/reference/for-inStatementsInvalid.errors.txt +++ b/tests/baselines/reference/for-inStatementsInvalid.errors.txt @@ -7,7 +7,6 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(1 tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.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/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(19,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/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(20,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/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(21,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/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(22,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/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(29,23): 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/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(38,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. @@ -16,7 +15,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(5 tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(62,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/conformance/statements/for-inStatements/for-inStatementsInvalid.ts (16 errors) ==== +==== tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts (15 errors) ==== var aNumber: number; for (aNumber in {}) { } ~~~~~~~ @@ -56,8 +55,6 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(6 ~~~~~~~~~~ !!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. for (var x in 42 ? d[x] : c[x]) { } - ~~~~~~~~~~~~~~~~ -!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. for (var x in c[23]) { } ~~~~~ !!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. diff --git a/tests/baselines/reference/forInBreakStatements.types b/tests/baselines/reference/forInBreakStatements.types index 7714429e5af42..4f4b9b3bef98a 100644 --- a/tests/baselines/reference/forInBreakStatements.types +++ b/tests/baselines/reference/forInBreakStatements.types @@ -1,7 +1,7 @@ === tests/cases/conformance/statements/breakStatements/forInBreakStatements.ts === for(var x in {}) { ->x : any +>x : string >{} : {} break; @@ -11,7 +11,7 @@ ONE: >ONE : any for(var x in {}) { ->x : any +>x : string >{} : {} break ONE; @@ -25,7 +25,7 @@ THREE: >THREE : any for(var x in {}) { ->x : any +>x : string >{} : {} break THREE; @@ -36,14 +36,14 @@ FOUR: >FOUR : any for(var x in {}) { ->x : any +>x : string >{} : {} FIVE: >FIVE : any for(var x in {}) { ->x : any +>x : string >{} : {} break FOUR; @@ -52,14 +52,14 @@ for(var x in {}) { } for(var x in {}) { ->x : any +>x : string >{} : {} SIX: >SIX : any for(var x in {}) break SIX; ->x : any +>x : string >{} : {} >SIX : any } @@ -68,11 +68,11 @@ SEVEN: >SEVEN : any for (var x in {}) for (var x in {}) for (var x in {}) break SEVEN; ->x : any +>x : string >{} : {} ->x : any +>x : string >{} : {} ->x : any +>x : string >{} : {} >SEVEN : any @@ -80,7 +80,7 @@ EIGHT: >EIGHT : any for (var x in {}){ ->x : any +>x : string >{} : {} var fn = function () { } diff --git a/tests/baselines/reference/forInContinueStatements.types b/tests/baselines/reference/forInContinueStatements.types index 572fd16053d33..e45cc7985429b 100644 --- a/tests/baselines/reference/forInContinueStatements.types +++ b/tests/baselines/reference/forInContinueStatements.types @@ -1,7 +1,7 @@ === tests/cases/conformance/statements/continueStatements/forInContinueStatements.ts === for(var x in {}) { ->x : any +>x : string >{} : {} continue; @@ -11,7 +11,7 @@ ONE: >ONE : any for(var x in {}) { ->x : any +>x : string >{} : {} continue ONE; @@ -25,7 +25,7 @@ THREE: >THREE : any for(var x in {}) { ->x : any +>x : string >{} : {} continue THREE; @@ -36,14 +36,14 @@ FOUR: >FOUR : any for(var x in {}) { ->x : any +>x : string >{} : {} FIVE: >FIVE : any for(var x in {}) { ->x : any +>x : string >{} : {} continue FOUR; @@ -52,14 +52,14 @@ for(var x in {}) { } for(var x in {}) { ->x : any +>x : string >{} : {} SIX: >SIX : any for(var x in {}) continue SIX; ->x : any +>x : string >{} : {} >SIX : any } @@ -68,11 +68,11 @@ SEVEN: >SEVEN : any for (var x in {}) for (var x in {}) for (var x in {}) continue SEVEN; ->x : any +>x : string >{} : {} ->x : any +>x : string >{} : {} ->x : any +>x : string >{} : {} >SEVEN : any @@ -80,7 +80,7 @@ EIGHT: >EIGHT : any for (var x in {}){ ->x : any +>x : string >{} : {} var fn = function () { } diff --git a/tests/baselines/reference/forInStatement1.types b/tests/baselines/reference/forInStatement1.types index 8ccacc9e2f77f..ed2e568a39ef1 100644 --- a/tests/baselines/reference/forInStatement1.types +++ b/tests/baselines/reference/forInStatement1.types @@ -3,6 +3,6 @@ var expr: any; >expr : any for (var a in expr) { ->a : any +>a : string >expr : any } diff --git a/tests/baselines/reference/forInStatement3.types b/tests/baselines/reference/forInStatement3.types index 1d3803065bd17..d3767790ed2e3 100644 --- a/tests/baselines/reference/forInStatement3.types +++ b/tests/baselines/reference/forInStatement3.types @@ -8,7 +8,7 @@ function F() { >T : T for (var a in expr) { ->a : any +>a : string >expr : T } } diff --git a/tests/baselines/reference/implicitAnyInCatch.types b/tests/baselines/reference/implicitAnyInCatch.types index cd0dd2d2423e2..015d41b123f68 100644 --- a/tests/baselines/reference/implicitAnyInCatch.types +++ b/tests/baselines/reference/implicitAnyInCatch.types @@ -12,7 +12,7 @@ try { } catch (error) { >2147024809 : number } for (var key in this) { } ->key : any +>key : string >this : any class C { @@ -22,7 +22,7 @@ class C { >temp : () => void for (var x in this) { ->x : any +>x : string >this : this } } diff --git a/tests/baselines/reference/inOperatorWithGeneric.types b/tests/baselines/reference/inOperatorWithGeneric.types index 2048e11082ab5..facdb7b50e246 100644 --- a/tests/baselines/reference/inOperatorWithGeneric.types +++ b/tests/baselines/reference/inOperatorWithGeneric.types @@ -9,7 +9,7 @@ class C { >T : T for (var p in x) { ->p : any +>p : string >x : T } } diff --git a/tests/baselines/reference/letDeclarations-es5.types b/tests/baselines/reference/letDeclarations-es5.types index 005e0b2615570..f6e8d418632d0 100644 --- a/tests/baselines/reference/letDeclarations-es5.types +++ b/tests/baselines/reference/letDeclarations-es5.types @@ -29,7 +29,7 @@ let l9 = 0, l10 :string = "", l11 = null; >null : null for(let l11 in {}) { } ->l11 : any +>l11 : string >{} : {} for(let l12 = 0; l12 < 9; l12++) { } diff --git a/tests/baselines/reference/letDeclarations.types b/tests/baselines/reference/letDeclarations.types index 55be4326b195e..bb20f895a14c5 100644 --- a/tests/baselines/reference/letDeclarations.types +++ b/tests/baselines/reference/letDeclarations.types @@ -29,7 +29,7 @@ let l9 = 0, l10 :string = "", l11 = null; >null : null for(let l11 in {}) { } ->l11 : any +>l11 : string >{} : {} for(let l12 = 0; l12 < 9; l12++) { } diff --git a/tests/baselines/reference/letInVarDeclOfForIn_ES5.types b/tests/baselines/reference/letInVarDeclOfForIn_ES5.types index ac1ca3f27c9a3..095ae16b91e9d 100644 --- a/tests/baselines/reference/letInVarDeclOfForIn_ES5.types +++ b/tests/baselines/reference/letInVarDeclOfForIn_ES5.types @@ -2,7 +2,7 @@ // should not be an error for (var let in [1,2,3]) {} ->let : any +>let : string >[1,2,3] : number[] >1 : number >2 : number @@ -10,7 +10,7 @@ for (var let in [1,2,3]) {} { for (var let in [1,2,3]) {} ->let : any +>let : string >[1,2,3] : number[] >1 : number >2 : number diff --git a/tests/baselines/reference/letInVarDeclOfForIn_ES6.types b/tests/baselines/reference/letInVarDeclOfForIn_ES6.types index 3c508bd8e2b9b..a5e2ce108db14 100644 --- a/tests/baselines/reference/letInVarDeclOfForIn_ES6.types +++ b/tests/baselines/reference/letInVarDeclOfForIn_ES6.types @@ -2,7 +2,7 @@ // should not be an error for (var let in [1,2,3]) {} ->let : any +>let : string >[1,2,3] : number[] >1 : number >2 : number @@ -10,7 +10,7 @@ for (var let in [1,2,3]) {} { for (var let in [1,2,3]) {} ->let : any +>let : string >[1,2,3] : number[] >1 : number >2 : number diff --git a/tests/baselines/reference/noImplicitAnyIndexing.errors.txt b/tests/baselines/reference/noImplicitAnyIndexing.errors.txt index 8b75459ebd06d..8f4cf616bda5f 100644 --- a/tests/baselines/reference/noImplicitAnyIndexing.errors.txt +++ b/tests/baselines/reference/noImplicitAnyIndexing.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/noImplicitAnyIndexing.ts(13,26): error TS7017: Index signature of object type implicitly has an 'any' type. +tests/cases/compiler/noImplicitAnyIndexing.ts(13,26): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. tests/cases/compiler/noImplicitAnyIndexing.ts(20,9): error TS7017: Index signature of object type implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyIndexing.ts(23,9): error TS7017: Index signature of object type implicitly has an 'any' type. tests/cases/compiler/noImplicitAnyIndexing.ts(31,10): error TS7017: Index signature of object type implicitly has an 'any' type. @@ -19,7 +19,7 @@ tests/cases/compiler/noImplicitAnyIndexing.ts(31,10): error TS7017: Index signat // Should be implicit 'any' ; property access fails, no string indexer. var strRepresentation3 = MyEmusEnum["monehh"]; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS7017: Index signature of object type implicitly has an 'any' type. +!!! error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. // Should be okay; should be a MyEmusEnum var strRepresentation4 = MyEmusEnum["emu"]; diff --git a/tests/baselines/reference/parserES5ForOfStatement19.errors.txt b/tests/baselines/reference/parserES5ForOfStatement19.errors.txt new file mode 100644 index 0000000000000..9d0bb02f1efb5 --- /dev/null +++ b/tests/baselines/reference/parserES5ForOfStatement19.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement19.ts(1,16): 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/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement19.ts (1 errors) ==== + for (var of in of) { } + ~~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ForOfStatement19.symbols b/tests/baselines/reference/parserES5ForOfStatement19.symbols deleted file mode 100644 index 93ba77e3db94c..0000000000000 --- a/tests/baselines/reference/parserES5ForOfStatement19.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement19.ts === -for (var of in of) { } ->of : Symbol(of, Decl(parserES5ForOfStatement19.ts, 0, 8)) ->of : Symbol(of, Decl(parserES5ForOfStatement19.ts, 0, 8)) - diff --git a/tests/baselines/reference/parserES5ForOfStatement19.types b/tests/baselines/reference/parserES5ForOfStatement19.types deleted file mode 100644 index 13abc7ae757b4..0000000000000 --- a/tests/baselines/reference/parserES5ForOfStatement19.types +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement19.ts === -for (var of in of) { } ->of : any ->of : any - diff --git a/tests/baselines/reference/parserES5ForOfStatement20.errors.txt b/tests/baselines/reference/parserES5ForOfStatement20.errors.txt index 4aee32394b60b..2bfc54590ad54 100644 --- a/tests/baselines/reference/parserES5ForOfStatement20.errors.txt +++ b/tests/baselines/reference/parserES5ForOfStatement20.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement20.ts(1,10): error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer. +tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement20.ts(1,20): 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/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement20.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement20.ts (2 errors) ==== for (var of = 0 in of) { } ~~ -!!! error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer. \ No newline at end of file +!!! error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer. + ~~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement19.errors.txt b/tests/baselines/reference/parserForOfStatement19.errors.txt new file mode 100644 index 0000000000000..a111498efe709 --- /dev/null +++ b/tests/baselines/reference/parserForOfStatement19.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement19.ts(1,16): 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/conformance/parser/ecmascript6/Iterators/parserForOfStatement19.ts (1 errors) ==== + for (var of in of) { } + ~~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. \ No newline at end of file diff --git a/tests/baselines/reference/parserForOfStatement19.symbols b/tests/baselines/reference/parserForOfStatement19.symbols deleted file mode 100644 index 1e123349e13c6..0000000000000 --- a/tests/baselines/reference/parserForOfStatement19.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement19.ts === -for (var of in of) { } ->of : Symbol(of, Decl(parserForOfStatement19.ts, 0, 8)) ->of : Symbol(of, Decl(parserForOfStatement19.ts, 0, 8)) - diff --git a/tests/baselines/reference/parserForOfStatement19.types b/tests/baselines/reference/parserForOfStatement19.types deleted file mode 100644 index 6fcc5e8f79216..0000000000000 --- a/tests/baselines/reference/parserForOfStatement19.types +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement19.ts === -for (var of in of) { } ->of : any ->of : any - diff --git a/tests/baselines/reference/parserForOfStatement20.errors.txt b/tests/baselines/reference/parserForOfStatement20.errors.txt index 461f307f6b936..f2b6ac39a8332 100644 --- a/tests/baselines/reference/parserForOfStatement20.errors.txt +++ b/tests/baselines/reference/parserForOfStatement20.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement20.ts(1,10): error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer. +tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement20.ts(1,20): 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/conformance/parser/ecmascript6/Iterators/parserForOfStatement20.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement20.ts (2 errors) ==== for (var of = 0 in of) { } ~~ -!!! error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer. \ No newline at end of file +!!! error TS1189: The variable declaration of a 'for...in' statement cannot have an initializer. + ~~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. \ No newline at end of file diff --git a/tests/baselines/reference/recursiveLetConst.errors.txt b/tests/baselines/reference/recursiveLetConst.errors.txt index 88ecb379e5ef8..6d3f15880bb96 100644 --- a/tests/baselines/reference/recursiveLetConst.errors.txt +++ b/tests/baselines/reference/recursiveLetConst.errors.txt @@ -5,13 +5,14 @@ tests/cases/compiler/recursiveLetConst.ts(5,14): error TS2448: Block-scoped vari tests/cases/compiler/recursiveLetConst.ts(6,14): error TS2448: Block-scoped variable 'v' used before its declaration. tests/cases/compiler/recursiveLetConst.ts(7,1): error TS7027: Unreachable code detected. tests/cases/compiler/recursiveLetConst.ts(7,16): error TS2448: Block-scoped variable 'v' used before its declaration. +tests/cases/compiler/recursiveLetConst.ts(8,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/recursiveLetConst.ts(8,15): error TS2448: Block-scoped variable 'v' used before its declaration. tests/cases/compiler/recursiveLetConst.ts(9,15): error TS2448: Block-scoped variable 'v' used before its declaration. tests/cases/compiler/recursiveLetConst.ts(10,17): error TS2448: Block-scoped variable 'v' used before its declaration. tests/cases/compiler/recursiveLetConst.ts(11,11): error TS2448: Block-scoped variable 'x2' used before its declaration. -==== tests/cases/compiler/recursiveLetConst.ts (11 errors) ==== +==== tests/cases/compiler/recursiveLetConst.ts (12 errors) ==== 'use strict' let x = x + 1; ~ @@ -35,6 +36,8 @@ tests/cases/compiler/recursiveLetConst.ts(11,11): error TS2448: Block-scoped var !!! error TS2448: Block-scoped variable 'v' used before its declaration. for (let v in v) { } ~ +!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter. + ~ !!! error TS2448: Block-scoped variable 'v' used before its declaration. for (let v of v) { } ~ diff --git a/tests/baselines/reference/throwInEnclosingStatements.types b/tests/baselines/reference/throwInEnclosingStatements.types index 568fd800e353f..32f0fb093bcd9 100644 --- a/tests/baselines/reference/throwInEnclosingStatements.types +++ b/tests/baselines/reference/throwInEnclosingStatements.types @@ -51,9 +51,9 @@ for (var i = 0; ;) { throw i; } >i : number for (var idx in {}) { throw idx; } ->idx : any +>idx : string >{} : {} ->idx : any +>idx : string do { throw null; }while(true) >null : null diff --git a/tests/cases/compiler/capturedLetConstInLoop5.ts b/tests/cases/compiler/capturedLetConstInLoop5.ts index 475137c14ccb2..5eedd5aac85b7 100644 --- a/tests/cases/compiler/capturedLetConstInLoop5.ts +++ b/tests/cases/compiler/capturedLetConstInLoop5.ts @@ -19,7 +19,7 @@ function foo00(x) { var v = x; (function() { return x + v }); (() => x + v); - if (x == 1) { + if (x == "1") { return; } } @@ -158,7 +158,7 @@ function foo00_c(x) { var v = x; (function() { return x + v }); (() => x + v); - if (x == 1) { + if (x == "1") { return; } } diff --git a/tests/cases/compiler/capturedLetConstInLoop5_ES6.ts b/tests/cases/compiler/capturedLetConstInLoop5_ES6.ts index 035e21b9e841c..224ffa823bf32 100644 --- a/tests/cases/compiler/capturedLetConstInLoop5_ES6.ts +++ b/tests/cases/compiler/capturedLetConstInLoop5_ES6.ts @@ -21,7 +21,7 @@ function foo00(x) { var v = x; (function() { return x + v }); (() => x + v); - if (x == 1) { + if (x == "1") { return; } } @@ -160,7 +160,7 @@ function foo00_c(x) { var v = x; (function() { return x + v }); (() => x + v); - if (x == 1) { + if (x == "1") { return; } } diff --git a/tests/cases/compiler/capturedLetConstInLoop6.ts b/tests/cases/compiler/capturedLetConstInLoop6.ts index 321d20e3c2060..a854be4619527 100644 --- a/tests/cases/compiler/capturedLetConstInLoop6.ts +++ b/tests/cases/compiler/capturedLetConstInLoop6.ts @@ -13,10 +13,10 @@ for (let x of []) { for (let x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 2) { + if (x == "2") { continue; } } @@ -132,10 +132,10 @@ for (const x of []) { for (const x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 2) { + if (x == "2") { continue; } } diff --git a/tests/cases/compiler/capturedLetConstInLoop6_ES6.ts b/tests/cases/compiler/capturedLetConstInLoop6_ES6.ts index f43fe5851d226..ad10f1fcb74f7 100644 --- a/tests/cases/compiler/capturedLetConstInLoop6_ES6.ts +++ b/tests/cases/compiler/capturedLetConstInLoop6_ES6.ts @@ -14,10 +14,10 @@ for (let x of []) { for (let x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 2) { + if (x == "2") { continue; } } @@ -133,10 +133,10 @@ for (const x of []) { for (const x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 2) { + if (x == "2") { continue; } } diff --git a/tests/cases/compiler/capturedLetConstInLoop7.ts b/tests/cases/compiler/capturedLetConstInLoop7.ts index a1d35c4038b7b..12805411f969f 100644 --- a/tests/cases/compiler/capturedLetConstInLoop7.ts +++ b/tests/cases/compiler/capturedLetConstInLoop7.ts @@ -21,16 +21,16 @@ l00: for (let x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 1) { + if (x == "1") { break l00; } - if (x == 2) { + if (x == "2") { continue; } - if (x == 2) { + if (x == "2") { continue l00; } } @@ -209,16 +209,16 @@ l00_c: for (const x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 1) { + if (x == "1") { break l00_c; } - if (x == 2) { + if (x == "2") { continue; } - if (x == 2) { + if (x == "2") { continue l00_c; } } diff --git a/tests/cases/compiler/capturedLetConstInLoop7_ES6.ts b/tests/cases/compiler/capturedLetConstInLoop7_ES6.ts index 14b1d0c85af0a..2e2784f9a16c0 100644 --- a/tests/cases/compiler/capturedLetConstInLoop7_ES6.ts +++ b/tests/cases/compiler/capturedLetConstInLoop7_ES6.ts @@ -22,16 +22,16 @@ l00: for (let x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 1) { + if (x == "1") { break l00; } - if (x == 2) { + if (x == "2") { continue; } - if (x == 2) { + if (x == "2") { continue l00; } } @@ -210,16 +210,16 @@ l00_c: for (const x in []) { (function() { return x}); (() => x); - if (x == 1) { + if (x == "1") { break; } - if (x == 1) { + if (x == "1") { break l00_c; } - if (x == 2) { + if (x == "2") { continue; } - if (x == 2) { + if (x == "2") { continue l00_c; } } diff --git a/tests/cases/conformance/statements/for-inStatements/for-inStatementsArray.ts b/tests/cases/conformance/statements/for-inStatements/for-inStatementsArray.ts new file mode 100644 index 0000000000000..6acf8d4b35515 --- /dev/null +++ b/tests/cases/conformance/statements/for-inStatements/for-inStatementsArray.ts @@ -0,0 +1,38 @@ +let a: Date[]; +let b: boolean[]; + +for (let x in a) { + let a1 = a[x]; + let a2 = a[(x)]; + let a3 = a[+x]; + let b1 = b[x]; + let b2 = b[(x)]; + let b3 = b[+x]; +} + +for (let x in a) { + for (let y in a) { + for (let z in a) { + let a1 = a[x]; + let a2 = a[y]; + let a3 = a[z]; + } + } +} + +let i: string; +let j: string; +for (i in a) { + for (j in b) { + let a1 = a[i]; + let a2 = a[j]; + } +} + +var s: string; +for (var s in a) { + let a1 = a[s]; +} +for (s in a) { + let a1 = a[s]; +} diff --git a/tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts b/tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts new file mode 100644 index 0000000000000..c87ab6cea03b9 --- /dev/null +++ b/tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts @@ -0,0 +1,19 @@ +// @noImplicitAny: true + +let a: Date[]; + +for (let x in a) { + let a1 = a[x + 1]; + let a2 = a[x - 1]; + if (x === 1) { + } + let a3 = x.unknownProperty; +} + +var i: number; +for (var i in a ) { +} + +var j: any; +for (var j in a ) { +} diff --git a/tests/cases/fourslash/forIn.ts b/tests/cases/fourslash/forIn.ts index e24e161d96b8c..855d35917c1de 100644 --- a/tests/cases/fourslash/forIn.ts +++ b/tests/cases/fourslash/forIn.ts @@ -5,4 +5,4 @@ goTo.marker(); -verify.quickInfoIs('var p: any', ""); +verify.quickInfoIs('var p: string', "");