From 31f8a8148c952fcc9716b2953d49c23715cc0438 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 5 Sep 2015 15:46:45 -0700 Subject: [PATCH] Adding test for excess/missing properties --- .../missingAndExcessProperties.errors.txt | 85 +++++++++++++++++++ .../reference/missingAndExcessProperties.js | 69 +++++++++++++++ .../missingAndExcessProperties.ts | 33 +++++++ 3 files changed, 187 insertions(+) create mode 100644 tests/baselines/reference/missingAndExcessProperties.errors.txt create mode 100644 tests/baselines/reference/missingAndExcessProperties.js create mode 100644 tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts diff --git a/tests/baselines/reference/missingAndExcessProperties.errors.txt b/tests/baselines/reference/missingAndExcessProperties.errors.txt new file mode 100644 index 0000000000000..294b564a23999 --- /dev/null +++ b/tests/baselines/reference/missingAndExcessProperties.errors.txt @@ -0,0 +1,85 @@ +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,11): error TS2459: Type '{}' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,14): error TS2459: Type '{}' has no property 'y' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,18): error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,11): error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): error TS2459: Type '{}' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2459: Type '{}' has no property 'y' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,17): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(20,23): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(21,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(22,19): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(29,14): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(29,20): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(30,22): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; }'. +tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: number; }'. + + +==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (16 errors) ==== + // Missing properties + function f1() { + var { x, y } = {}; + ~ +!!! error TS2459: Type '{}' has no property 'x' and no string index signature. + ~ +!!! error TS2459: Type '{}' has no property 'y' and no string index signature. + var { x = 1, y } = {}; + ~ +!!! error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. + var { x, y = 1 } = {}; + ~ +!!! error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. + var { x = 1, y = 1 } = {}; + } + + // Missing properties + function f2() { + var x: number, y: number; + ({ x, y } = {}); + ~ +!!! error TS2459: Type '{}' has no property 'x' and no string index signature. + ~ +!!! error TS2459: Type '{}' has no property 'y' and no string index signature. + ({ x: x = 1, y } = {}); + ~ +!!! error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature. + ({ x, y: y = 1 } = {}); + ~ +!!! error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature. + ({ x: x = 1, y: y = 1 } = {}); + } + + // Excess properties + function f3() { + var { } = { x: 0, y: 0 }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + var { x } = { x: 0, y: 0 }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'. + var { y } = { x: 0, y: 0 }; + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'. + var { x, y } = { x: 0, y: 0 }; + } + + // Excess properties + function f4() { + var x: number, y: number; + ({ } = { x: 0, y: 0 }); + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'. + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'. + ({ x } = { x: 0, y: 0 }); + ~ +!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; }'. + ({ y } = { x: 0, y: 0 }); + ~ +!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: number; }'. + ({ x, y } = { x: 0, y: 0 }); + } + \ No newline at end of file diff --git a/tests/baselines/reference/missingAndExcessProperties.js b/tests/baselines/reference/missingAndExcessProperties.js new file mode 100644 index 0000000000000..b9fcadd9519ea --- /dev/null +++ b/tests/baselines/reference/missingAndExcessProperties.js @@ -0,0 +1,69 @@ +//// [missingAndExcessProperties.ts] +// Missing properties +function f1() { + var { x, y } = {}; + var { x = 1, y } = {}; + var { x, y = 1 } = {}; + var { x = 1, y = 1 } = {}; +} + +// Missing properties +function f2() { + var x: number, y: number; + ({ x, y } = {}); + ({ x: x = 1, y } = {}); + ({ x, y: y = 1 } = {}); + ({ x: x = 1, y: y = 1 } = {}); +} + +// Excess properties +function f3() { + var { } = { x: 0, y: 0 }; + var { x } = { x: 0, y: 0 }; + var { y } = { x: 0, y: 0 }; + var { x, y } = { x: 0, y: 0 }; +} + +// Excess properties +function f4() { + var x: number, y: number; + ({ } = { x: 0, y: 0 }); + ({ x } = { x: 0, y: 0 }); + ({ y } = { x: 0, y: 0 }); + ({ x, y } = { x: 0, y: 0 }); +} + + +//// [missingAndExcessProperties.js] +// Missing properties +function f1() { + var _a = {}, x = _a.x, y = _a.y; + var _b = {}, _c = _b.x, x = _c === void 0 ? 1 : _c, y = _b.y; + var _d = {}, x = _d.x, _e = _d.y, y = _e === void 0 ? 1 : _e; + var _f = {}, _g = _f.x, x = _g === void 0 ? 1 : _g, _h = _f.y, y = _h === void 0 ? 1 : _h; +} +// Missing properties +function f2() { + var x, y; + (_a = {}, x = _a.x, y = _a.y, _a); + (_b = {}, _c = _b.x, x = _c === void 0 ? 1 : _c, y = _b.y, _b); + (_d = {}, x = _d.x, _e = _d.y, y = _e === void 0 ? 1 : _e, _d); + (_f = {}, _g = _f.x, x = _g === void 0 ? 1 : _g, _h = _f.y, y = _h === void 0 ? 1 : _h, _f); + var _a, _b, _c, _d, _e, _f, _g, _h; +} +// Excess properties +function f3() { + var _a = { x: 0, y: 0 }; + var x = { x: 0, y: 0 }.x; + var y = { x: 0, y: 0 }.y; + var _b = { x: 0, y: 0 }, x = _b.x, y = _b.y; +} +// Excess properties +function f4() { + var x, y; + ({ x: 0, y: 0 }); + (_a = { x: 0, y: 0 }, x = _a.x, _a); + (_b = { x: 0, y: 0 }, y = _b.y, _b); + (_c = { x: 0, y: 0 }, x = _c.x, y = _c.y, _c); + var _a, _b, _c; +} diff --git a/tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts b/tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts new file mode 100644 index 0000000000000..ef91b8249da11 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts @@ -0,0 +1,33 @@ +// Missing properties +function f1() { + var { x, y } = {}; + var { x = 1, y } = {}; + var { x, y = 1 } = {}; + var { x = 1, y = 1 } = {}; +} + +// Missing properties +function f2() { + var x: number, y: number; + ({ x, y } = {}); + ({ x: x = 1, y } = {}); + ({ x, y: y = 1 } = {}); + ({ x: x = 1, y: y = 1 } = {}); +} + +// Excess properties +function f3() { + var { } = { x: 0, y: 0 }; + var { x } = { x: 0, y: 0 }; + var { y } = { x: 0, y: 0 }; + var { x, y } = { x: 0, y: 0 }; +} + +// Excess properties +function f4() { + var x: number, y: number; + ({ } = { x: 0, y: 0 }); + ({ x } = { x: 0, y: 0 }); + ({ y } = { x: 0, y: 0 }); + ({ x, y } = { x: 0, y: 0 }); +}