Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object literal freshness errors with spreads #13900

Merged
merged 1 commit into from
May 17, 2017
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
2 changes: 2 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11864,6 +11864,8 @@ namespace ts {
if (spread.flags & TypeFlags.Object) {
// only set the symbol and flags if this is a (fresh) object type
spread.flags |= propagatedFlags;
spread.flags |= TypeFlags.FreshLiteral;
(spread as ObjectType).objectFlags |= ObjectFlags.ObjectLiteral;
spread.symbol = node.symbol;
}
return spread;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
tests/cases/compiler/objectLiteralFreshnessWithSpread.ts(2,35): error TS2322: Type '{ z: number; b: number; extra: number; a: number; }' is not assignable to type '{ a: any; b: any; }'.
Object literal may only specify known properties, and 'z' does not exist in type '{ a: any; b: any; }'.


==== tests/cases/compiler/objectLiteralFreshnessWithSpread.ts (1 errors) ====
let x = { b: 1, extra: 2 }
let xx: { a, b } = { a: 1, ...x, z: 3 } // error for 'z', no error for 'extra'
~~~~
!!! error TS2322: Type '{ z: number; b: number; extra: number; a: number; }' is not assignable to type '{ a: any; b: any; }'.
!!! error TS2322: Object literal may only specify known properties, and 'z' does not exist in type '{ a: any; b: any; }'.

16 changes: 16 additions & 0 deletions tests/baselines/reference/objectLiteralFreshnessWithSpread.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [objectLiteralFreshnessWithSpread.ts]
let x = { b: 1, extra: 2 }
let xx: { a, b } = { a: 1, ...x, z: 3 } // error for 'z', no error for 'extra'


//// [objectLiteralFreshnessWithSpread.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;
};
var x = { b: 1, extra: 2 };
var xx = __assign({ a: 1 }, x, { z: 3 }); // error for 'z', no error for 'extra'
2 changes: 2 additions & 0 deletions tests/cases/compiler/objectLiteralFreshnessWithSpread.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let x = { b: 1, extra: 2 }
let xx: { a, b } = { a: 1, ...x, z: 3 } // error for 'z', no error for 'extra'