Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11252,13 +11252,7 @@ namespace ts {
}

function checkSpreadExpression(node: SpreadElement, contextualMapper?: TypeMapper): Type {
// It is usually not safe to call checkExpressionCached if we can be contextually typing.
// You can tell that we are contextually typing because of the contextualMapper parameter.
// While it is true that a spread element can have a contextual type, it does not do anything
// with this type. It is neither affected by it, nor does it propagate it to its operand.
// So the fact that contextualMapper is passed is not important, because the operand of a spread
// element is not contextually typed.
const arrayOrIterableType = checkExpressionCached(node.expression, contextualMapper);
const arrayOrIterableType = checkExpression(node.expression, contextualMapper);
return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, /*allowStringInput*/ false);
}

Expand Down
14 changes: 14 additions & 0 deletions tests/baselines/reference/selfReferencingSpreadInLoop.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests/cases/compiler/selfReferencingSpreadInLoop.ts(1,5): error TS7034: Variable 'additional' implicitly has type 'any[]' in some locations where its type cannot be determined.
tests/cases/compiler/selfReferencingSpreadInLoop.ts(3,22): error TS7005: Variable 'additional' implicitly has an 'any[]' type.


==== tests/cases/compiler/selfReferencingSpreadInLoop.ts (2 errors) ====
let additional = [];
~~~~~~~~~~
!!! error TS7034: Variable 'additional' implicitly has type 'any[]' in some locations where its type cannot be determined.
for (const subcomponent of [1, 2, 3]) {
additional = [...additional, subcomponent];
~~~~~~~~~~
!!! error TS7005: Variable 'additional' implicitly has an 'any[]' type.
}

13 changes: 13 additions & 0 deletions tests/baselines/reference/selfReferencingSpreadInLoop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [selfReferencingSpreadInLoop.ts]
let additional = [];
for (const subcomponent of [1, 2, 3]) {
additional = [...additional, subcomponent];
}


//// [selfReferencingSpreadInLoop.js]
var additional = [];
for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) {
var subcomponent = _a[_i];
additional = additional.concat([subcomponent]);
}
5 changes: 5 additions & 0 deletions tests/cases/compiler/selfReferencingSpreadInLoop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @noImplicitAny: true
let additional = [];
for (const subcomponent of [1, 2, 3]) {
additional = [...additional, subcomponent];
}