Test synthetic properties w/hasExcessProperties

This commit is contained in:
Nathan Shively-Sanders 2017-06-08 14:19:06 -07:00
parent 70069aeb31
commit d3f2234529
3 changed files with 76 additions and 0 deletions

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 });