Merge pull request #16377 from Microsoft/fix-synthetic-properties-in-hasExcessProperties

Fix synthetic properties in hasExcessProperties
This commit is contained in:
Nathan Shively-Sanders 2017-06-08 15:49:51 -07:00 committed by GitHub
commit ffc899ed38
4 changed files with 79 additions and 1 deletions

View File

@ -8977,7 +8977,9 @@ namespace ts {
reportError(Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target));
}
else {
errorNode = prop.valueDeclaration;
if (prop.valueDeclaration) {
errorNode = prop.valueDeclaration;
}
reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1,
symbolToString(prop), typeToString(target));
}

View File

@ -0,0 +1,30 @@
tests/cases/compiler/excessPropertyCheckWithSpread.ts(6,3): error TS2345: Argument of type '{ n: number; a: number; }' is not assignable to parameter of type '{ a: any; }'.
Object literal may only specify known properties, and 'n' does not exist in type '{ a: any; }'.
tests/cases/compiler/excessPropertyCheckWithSpread.ts(16,3): error TS2345: Argument of type '{ opt: string | number; a: number; }' is not assignable to parameter of type '{ a: any; }'.
Object literal may only specify known properties, and 'opt' does not exist in type '{ a: any; }'.
==== tests/cases/compiler/excessPropertyCheckWithSpread.ts (2 errors) ====
declare function f({ a: number }): void
interface I {
readonly n: number;
}
declare let i: I;
f({ a: 1, ...i });
~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ n: number; a: number; }' is not assignable to parameter of type '{ a: any; }'.
!!! error TS2345: Object literal may only specify known properties, and 'n' does not exist in type '{ a: any; }'.
interface R {
opt?: number
}
interface L {
opt: string
}
declare let l: L;
declare let r: R;
f({ a: 1, ...l, ...r });
~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ opt: string | number; a: number; }' is not assignable to parameter of type '{ a: any; }'.
!!! error TS2345: Object literal may only specify known properties, and 'opt' does not exist in type '{ a: any; }'.

View File

@ -0,0 +1,30 @@
//// [excessPropertyCheckWithSpread.ts]
declare function f({ a: number }): void
interface I {
readonly n: number;
}
declare let i: I;
f({ a: 1, ...i });
interface R {
opt?: number
}
interface L {
opt: string
}
declare let l: L;
declare let r: R;
f({ a: 1, ...l, ...r });
//// [excessPropertyCheckWithSpread.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;
};
f(__assign({ a: 1 }, i));
f(__assign({ a: 1 }, l, r));

View File

@ -0,0 +1,16 @@
declare function f({ a: number }): void
interface I {
readonly n: number;
}
declare let i: I;
f({ a: 1, ...i });
interface R {
opt?: number
}
interface L {
opt: string
}
declare let l: L;
declare let r: R;
f({ a: 1, ...l, ...r });