Skip to content

Commit ae2a13c

Browse files
authored
Merge pull request #12896 from Microsoft/implicit-any-error-on-explicit-any
Set symbol/flags only on (fresh) object spreads
2 parents e68161a + 587ba8d commit ae2a13c

File tree

6 files changed

+44
-3
lines changed

6 files changed

+44
-3
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11638,8 +11638,11 @@ namespace ts {
1163811638
if (propertiesArray.length > 0) {
1163911639
spread = getSpreadType(spread, createObjectLiteralType(), /*isFromObjectLiteral*/ true);
1164011640
}
11641-
spread.flags |= propagatedFlags;
11642-
spread.symbol = node.symbol;
11641+
if (spread.flags & TypeFlags.Object) {
11642+
// only set the symbol and flags if this is a (fresh) object type
11643+
spread.flags |= propagatedFlags;
11644+
spread.symbol = node.symbol;
11645+
}
1164311646
return spread;
1164411647
}
1164511648

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [explicitAnyAfterSpreadNoImplicitAnyError.ts]
2+
({ a: [], ...(null as any) });
3+
let x: any;
4+
5+
6+
//// [explicitAnyAfterSpreadNoImplicitAnyError.js]
7+
var __assign = (this && this.__assign) || Object.assign || function(t) {
8+
for (var s, i = 1, n = arguments.length; i < n; i++) {
9+
s = arguments[i];
10+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11+
t[p] = s[p];
12+
}
13+
return t;
14+
};
15+
(__assign({ a: [] }, null));
16+
var x;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/explicitAnyAfterSpreadNoImplicitAnyError.ts ===
2+
({ a: [], ...(null as any) });
3+
>a : Symbol(a, Decl(explicitAnyAfterSpreadNoImplicitAnyError.ts, 0, 2))
4+
5+
let x: any;
6+
>x : Symbol(x, Decl(explicitAnyAfterSpreadNoImplicitAnyError.ts, 1, 3))
7+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/explicitAnyAfterSpreadNoImplicitAnyError.ts ===
2+
({ a: [], ...(null as any) });
3+
>({ a: [], ...(null as any) }) : any
4+
>{ a: [], ...(null as any) } : any
5+
>a : undefined[]
6+
>[] : undefined[]
7+
>(null as any) : any
8+
>null as any : any
9+
>null : null
10+
11+
let x: any;
12+
>x : any
13+

tests/baselines/reference/objectSpread.symbols

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ let cplus: { p: number, plus(): void } = { ...c, plus() { return this.p + 1; } }
200200
>plus : Symbol(plus, Decl(objectSpread.ts, 49, 23))
201201
>c : Symbol(c, Decl(objectSpread.ts, 45, 3))
202202
>plus : Symbol(plus, Decl(objectSpread.ts, 49, 48))
203-
>this : Symbol(__object, Decl(objectSpread.ts, 41, 15))
204203

205204
cplus.plus();
206205
>cplus.plus : Symbol(plus, Decl(objectSpread.ts, 49, 23))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @noImplicitAny: true
2+
({ a: [], ...(null as any) });
3+
let x: any;

0 commit comments

Comments
 (0)