Merge pull request #12896 from Microsoft/implicit-any-error-on-explicit-any

Set symbol/flags only on (fresh) object spreads
This commit is contained in:
Nathan Shively-Sanders 2016-12-13 14:15:52 -08:00 committed by GitHub
commit ae2a13cf18
6 changed files with 44 additions and 3 deletions

View file

@ -11638,8 +11638,11 @@ namespace ts {
if (propertiesArray.length > 0) {
spread = getSpreadType(spread, createObjectLiteralType(), /*isFromObjectLiteral*/ true);
}
spread.flags |= propagatedFlags;
spread.symbol = node.symbol;
if (spread.flags & TypeFlags.Object) {
// only set the symbol and flags if this is a (fresh) object type
spread.flags |= propagatedFlags;
spread.symbol = node.symbol;
}
return spread;
}

View file

@ -0,0 +1,16 @@
//// [explicitAnyAfterSpreadNoImplicitAnyError.ts]
({ a: [], ...(null as any) });
let x: any;
//// [explicitAnyAfterSpreadNoImplicitAnyError.js]
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
(__assign({ a: [] }, null));
var x;

View file

@ -0,0 +1,7 @@
=== tests/cases/compiler/explicitAnyAfterSpreadNoImplicitAnyError.ts ===
({ a: [], ...(null as any) });
>a : Symbol(a, Decl(explicitAnyAfterSpreadNoImplicitAnyError.ts, 0, 2))
let x: any;
>x : Symbol(x, Decl(explicitAnyAfterSpreadNoImplicitAnyError.ts, 1, 3))

View file

@ -0,0 +1,13 @@
=== tests/cases/compiler/explicitAnyAfterSpreadNoImplicitAnyError.ts ===
({ a: [], ...(null as any) });
>({ a: [], ...(null as any) }) : any
>{ a: [], ...(null as any) } : any
>a : undefined[]
>[] : undefined[]
>(null as any) : any
>null as any : any
>null : null
let x: any;
>x : any

View file

@ -200,7 +200,6 @@ let cplus: { p: number, plus(): void } = { ...c, plus() { return this.p + 1; } }
>plus : Symbol(plus, Decl(objectSpread.ts, 49, 23))
>c : Symbol(c, Decl(objectSpread.ts, 45, 3))
>plus : Symbol(plus, Decl(objectSpread.ts, 49, 48))
>this : Symbol(__object, Decl(objectSpread.ts, 41, 15))
cplus.plus();
>cplus.plus : Symbol(plus, Decl(objectSpread.ts, 49, 23))

View file

@ -0,0 +1,3 @@
// @noImplicitAny: true
({ a: [], ...(null as any) });
let x: any;