From d3f2234529a9e2d45fb4a2315fd03d2092478bce Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 8 Jun 2017 14:19:06 -0700 Subject: [PATCH] Test synthetic properties w/hasExcessProperties --- .../excessPropertyCheckWithSpread.errors.txt | 30 +++++++++++++++++++ .../excessPropertyCheckWithSpread.js | 30 +++++++++++++++++++ .../compiler/excessPropertyCheckWithSpread.ts | 16 ++++++++++ 3 files changed, 76 insertions(+) create mode 100644 tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt create mode 100644 tests/baselines/reference/excessPropertyCheckWithSpread.js create mode 100644 tests/cases/compiler/excessPropertyCheckWithSpread.ts diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt new file mode 100644 index 0000000000..422d7fc280 --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt @@ -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; }'. + \ No newline at end of file diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.js b/tests/baselines/reference/excessPropertyCheckWithSpread.js new file mode 100644 index 0000000000..d8dac07a3f --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.js @@ -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)); diff --git a/tests/cases/compiler/excessPropertyCheckWithSpread.ts b/tests/cases/compiler/excessPropertyCheckWithSpread.ts new file mode 100644 index 0000000000..11c573b4ce --- /dev/null +++ b/tests/cases/compiler/excessPropertyCheckWithSpread.ts @@ -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 });