Skip to content

Commit 31f8a81

Browse files
committed
Adding test for excess/missing properties
1 parent f801420 commit 31f8a81

File tree

3 files changed

+187
-0
lines changed

3 files changed

+187
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,11): error TS2459: Type '{}' has no property 'x' and no string index signature.
2+
tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(3,14): error TS2459: Type '{}' has no property 'y' and no string index signature.
3+
tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(4,18): error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature.
4+
tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(5,11): error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature.
5+
tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,8): error TS2459: Type '{}' has no property 'x' and no string index signature.
6+
tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(12,11): error TS2459: Type '{}' has no property 'y' and no string index signature.
7+
tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(13,18): error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature.
8+
tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(14,8): error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature.
9+
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 '{}'.
10+
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 '{}'.
11+
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; }'.
12+
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; }'.
13+
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 '{}'.
14+
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 '{}'.
15+
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; }'.
16+
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; }'.
17+
18+
19+
==== tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts (16 errors) ====
20+
// Missing properties
21+
function f1() {
22+
var { x, y } = {};
23+
~
24+
!!! error TS2459: Type '{}' has no property 'x' and no string index signature.
25+
~
26+
!!! error TS2459: Type '{}' has no property 'y' and no string index signature.
27+
var { x = 1, y } = {};
28+
~
29+
!!! error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature.
30+
var { x, y = 1 } = {};
31+
~
32+
!!! error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature.
33+
var { x = 1, y = 1 } = {};
34+
}
35+
36+
// Missing properties
37+
function f2() {
38+
var x: number, y: number;
39+
({ x, y } = {});
40+
~
41+
!!! error TS2459: Type '{}' has no property 'x' and no string index signature.
42+
~
43+
!!! error TS2459: Type '{}' has no property 'y' and no string index signature.
44+
({ x: x = 1, y } = {});
45+
~
46+
!!! error TS2459: Type '{ x?: number; }' has no property 'y' and no string index signature.
47+
({ x, y: y = 1 } = {});
48+
~
49+
!!! error TS2459: Type '{ y?: number; }' has no property 'x' and no string index signature.
50+
({ x: x = 1, y: y = 1 } = {});
51+
}
52+
53+
// Excess properties
54+
function f3() {
55+
var { } = { x: 0, y: 0 };
56+
~
57+
!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'.
58+
~
59+
!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'.
60+
var { x } = { x: 0, y: 0 };
61+
~
62+
!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: any; }'.
63+
var { y } = { x: 0, y: 0 };
64+
~
65+
!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: any; }'.
66+
var { x, y } = { x: 0, y: 0 };
67+
}
68+
69+
// Excess properties
70+
function f4() {
71+
var x: number, y: number;
72+
({ } = { x: 0, y: 0 });
73+
~
74+
!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{}'.
75+
~
76+
!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{}'.
77+
({ x } = { x: 0, y: 0 });
78+
~
79+
!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; }'.
80+
({ y } = { x: 0, y: 0 });
81+
~
82+
!!! error TS2353: Object literal may only specify known properties, and 'x' does not exist in type '{ y: number; }'.
83+
({ x, y } = { x: 0, y: 0 });
84+
}
85+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//// [missingAndExcessProperties.ts]
2+
// Missing properties
3+
function f1() {
4+
var { x, y } = {};
5+
var { x = 1, y } = {};
6+
var { x, y = 1 } = {};
7+
var { x = 1, y = 1 } = {};
8+
}
9+
10+
// Missing properties
11+
function f2() {
12+
var x: number, y: number;
13+
({ x, y } = {});
14+
({ x: x = 1, y } = {});
15+
({ x, y: y = 1 } = {});
16+
({ x: x = 1, y: y = 1 } = {});
17+
}
18+
19+
// Excess properties
20+
function f3() {
21+
var { } = { x: 0, y: 0 };
22+
var { x } = { x: 0, y: 0 };
23+
var { y } = { x: 0, y: 0 };
24+
var { x, y } = { x: 0, y: 0 };
25+
}
26+
27+
// Excess properties
28+
function f4() {
29+
var x: number, y: number;
30+
({ } = { x: 0, y: 0 });
31+
({ x } = { x: 0, y: 0 });
32+
({ y } = { x: 0, y: 0 });
33+
({ x, y } = { x: 0, y: 0 });
34+
}
35+
36+
37+
//// [missingAndExcessProperties.js]
38+
// Missing properties
39+
function f1() {
40+
var _a = {}, x = _a.x, y = _a.y;
41+
var _b = {}, _c = _b.x, x = _c === void 0 ? 1 : _c, y = _b.y;
42+
var _d = {}, x = _d.x, _e = _d.y, y = _e === void 0 ? 1 : _e;
43+
var _f = {}, _g = _f.x, x = _g === void 0 ? 1 : _g, _h = _f.y, y = _h === void 0 ? 1 : _h;
44+
}
45+
// Missing properties
46+
function f2() {
47+
var x, y;
48+
(_a = {}, x = _a.x, y = _a.y, _a);
49+
(_b = {}, _c = _b.x, x = _c === void 0 ? 1 : _c, y = _b.y, _b);
50+
(_d = {}, x = _d.x, _e = _d.y, y = _e === void 0 ? 1 : _e, _d);
51+
(_f = {}, _g = _f.x, x = _g === void 0 ? 1 : _g, _h = _f.y, y = _h === void 0 ? 1 : _h, _f);
52+
var _a, _b, _c, _d, _e, _f, _g, _h;
53+
}
54+
// Excess properties
55+
function f3() {
56+
var _a = { x: 0, y: 0 };
57+
var x = { x: 0, y: 0 }.x;
58+
var y = { x: 0, y: 0 }.y;
59+
var _b = { x: 0, y: 0 }, x = _b.x, y = _b.y;
60+
}
61+
// Excess properties
62+
function f4() {
63+
var x, y;
64+
({ x: 0, y: 0 });
65+
(_a = { x: 0, y: 0 }, x = _a.x, _a);
66+
(_b = { x: 0, y: 0 }, y = _b.y, _b);
67+
(_c = { x: 0, y: 0 }, x = _c.x, y = _c.y, _c);
68+
var _a, _b, _c;
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Missing properties
2+
function f1() {
3+
var { x, y } = {};
4+
var { x = 1, y } = {};
5+
var { x, y = 1 } = {};
6+
var { x = 1, y = 1 } = {};
7+
}
8+
9+
// Missing properties
10+
function f2() {
11+
var x: number, y: number;
12+
({ x, y } = {});
13+
({ x: x = 1, y } = {});
14+
({ x, y: y = 1 } = {});
15+
({ x: x = 1, y: y = 1 } = {});
16+
}
17+
18+
// Excess properties
19+
function f3() {
20+
var { } = { x: 0, y: 0 };
21+
var { x } = { x: 0, y: 0 };
22+
var { y } = { x: 0, y: 0 };
23+
var { x, y } = { x: 0, y: 0 };
24+
}
25+
26+
// Excess properties
27+
function f4() {
28+
var x: number, y: number;
29+
({ } = { x: 0, y: 0 });
30+
({ x } = { x: 0, y: 0 });
31+
({ y } = { x: 0, y: 0 });
32+
({ x, y } = { x: 0, y: 0 });
33+
}

0 commit comments

Comments
 (0)