Skip to content

Commit d45768e

Browse files
committed
Test a setter
1 parent 5eb70f8 commit d45768e

5 files changed

+446
-298
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,135 @@
11
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
2-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(14,15): error TS2339: Property 'bar' does not exist on type 'Omit<this, "bar" | "func">'.
3-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(15,15): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'.
4-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(16,15): error TS2339: Property 'bar' does not exist on type 'Omit<this, "foo" | "bar" | "func">'.
5-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(17,15): error TS2339: Property 'bar' does not exist on type '{}'.
6-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(19,15): error TS2339: Property 'func' does not exist on type 'Omit<this, "bar" | "func">'.
7-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(20,15): error TS2339: Property 'func' does not exist on type '{ foo: string; }'.
8-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(21,15): error TS2339: Property 'func' does not exist on type 'Omit<this, "foo" | "bar" | "func">'.
9-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(22,15): error TS2339: Property 'func' does not exist on type '{}'.
10-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(32,11): error TS2339: Property 'bar' does not exist on type 'Omit<T, "bar" | "func">'.
11-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(33,11): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'.
12-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(34,11): error TS2339: Property 'bar' does not exist on type 'Omit<T, "foo" | "bar" | "func">'.
13-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(35,11): error TS2339: Property 'bar' does not exist on type '{}'.
14-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(37,11): error TS2339: Property 'func' does not exist on type 'Omit<T, "bar" | "func">'.
15-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(38,11): error TS2339: Property 'func' does not exist on type '{ foo: string; }'.
16-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(39,11): error TS2339: Property 'func' does not exist on type 'Omit<T, "foo" | "bar" | "func">'.
17-
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(40,11): error TS2339: Property 'func' does not exist on type '{}'.
2+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
3+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(16,15): error TS2339: Property 'getter' does not exist on type 'Omit<this, "getter" | "setter" | "method">'.
4+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(17,15): error TS2339: Property 'getter' does not exist on type '{ normal: string; }'.
5+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(18,15): error TS2339: Property 'getter' does not exist on type 'Omit<this, "normal" | "getter" | "setter" | "method">'.
6+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(19,15): error TS2339: Property 'getter' does not exist on type '{}'.
7+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(21,15): error TS2339: Property 'setter' does not exist on type 'Omit<this, "getter" | "setter" | "method">'.
8+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(22,15): error TS2339: Property 'setter' does not exist on type '{ normal: string; }'.
9+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(23,15): error TS2339: Property 'setter' does not exist on type 'Omit<this, "normal" | "getter" | "setter" | "method">'.
10+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(24,15): error TS2339: Property 'setter' does not exist on type '{}'.
11+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(26,15): error TS2339: Property 'method' does not exist on type 'Omit<this, "getter" | "setter" | "method">'.
12+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(27,15): error TS2339: Property 'method' does not exist on type '{ normal: string; }'.
13+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(28,15): error TS2339: Property 'method' does not exist on type 'Omit<this, "normal" | "getter" | "setter" | "method">'.
14+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(29,15): error TS2339: Property 'method' does not exist on type '{}'.
15+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(39,11): error TS2339: Property 'getter' does not exist on type 'Omit<T, "getter" | "setter" | "method">'.
16+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(40,11): error TS2339: Property 'getter' does not exist on type '{ normal: string; }'.
17+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(41,11): error TS2339: Property 'getter' does not exist on type 'Omit<T, "normal" | "getter" | "setter" | "method">'.
18+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(42,11): error TS2339: Property 'getter' does not exist on type '{}'.
19+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(44,11): error TS2339: Property 'setter' does not exist on type 'Omit<T, "getter" | "setter" | "method">'.
20+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(45,11): error TS2339: Property 'setter' does not exist on type '{ normal: string; }'.
21+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(46,11): error TS2339: Property 'setter' does not exist on type 'Omit<T, "normal" | "getter" | "setter" | "method">'.
22+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(47,11): error TS2339: Property 'setter' does not exist on type '{}'.
23+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(49,11): error TS2339: Property 'method' does not exist on type 'Omit<T, "getter" | "setter" | "method">'.
24+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(50,11): error TS2339: Property 'method' does not exist on type '{ normal: string; }'.
25+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(51,11): error TS2339: Property 'method' does not exist on type 'Omit<T, "normal" | "getter" | "setter" | "method">'.
26+
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(52,11): error TS2339: Property 'method' does not exist on type '{}'.
1827

1928

20-
==== tests/cases/compiler/destructuringUnspreadableIntoRest.ts (17 errors) ====
29+
==== tests/cases/compiler/destructuringUnspreadableIntoRest.ts (26 errors) ====
2130
class A {
22-
constructor(public foo: string) {}
31+
constructor(public normal: string) {}
2332

24-
get bar(): number {
25-
~~~
33+
get getter(): number {
34+
~~~~~~
2635
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
2736
return 1;
2837
}
2938

30-
func() {
39+
set setter(_v: number) {}
40+
~~~~~~
41+
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
42+
43+
method() {
3144
const { ...rest1 } = this;
3245
const { ...rest2 } = this as A;
33-
const { foo: _f1, ...rest3 } = this;
34-
const { foo: _f2, ...rest4 } = this as A;
46+
const { normal: _1, ...rest3 } = this;
47+
const { normal: _2, ...rest4 } = this as A;
3548

36-
rest1.bar;
37-
~~~
38-
!!! error TS2339: Property 'bar' does not exist on type 'Omit<this, "bar" | "func">'.
39-
rest2.bar;
40-
~~~
41-
!!! error TS2339: Property 'bar' does not exist on type '{ foo: string; }'.
42-
rest3.bar;
43-
~~~
44-
!!! error TS2339: Property 'bar' does not exist on type 'Omit<this, "foo" | "bar" | "func">'.
45-
rest4.bar;
46-
~~~
47-
!!! error TS2339: Property 'bar' does not exist on type '{}'.
49+
rest1.getter;
50+
~~~~~~
51+
!!! error TS2339: Property 'getter' does not exist on type 'Omit<this, "getter" | "setter" | "method">'.
52+
rest2.getter;
53+
~~~~~~
54+
!!! error TS2339: Property 'getter' does not exist on type '{ normal: string; }'.
55+
rest3.getter;
56+
~~~~~~
57+
!!! error TS2339: Property 'getter' does not exist on type 'Omit<this, "normal" | "getter" | "setter" | "method">'.
58+
rest4.getter;
59+
~~~~~~
60+
!!! error TS2339: Property 'getter' does not exist on type '{}'.
4861

49-
rest1.func;
50-
~~~~
51-
!!! error TS2339: Property 'func' does not exist on type 'Omit<this, "bar" | "func">'.
52-
rest2.func;
53-
~~~~
54-
!!! error TS2339: Property 'func' does not exist on type '{ foo: string; }'.
55-
rest3.func;
56-
~~~~
57-
!!! error TS2339: Property 'func' does not exist on type 'Omit<this, "foo" | "bar" | "func">'.
58-
rest4.func;
59-
~~~~
60-
!!! error TS2339: Property 'func' does not exist on type '{}'.
62+
rest1.setter;
63+
~~~~~~
64+
!!! error TS2339: Property 'setter' does not exist on type 'Omit<this, "getter" | "setter" | "method">'.
65+
rest2.setter;
66+
~~~~~~
67+
!!! error TS2339: Property 'setter' does not exist on type '{ normal: string; }'.
68+
rest3.setter;
69+
~~~~~~
70+
!!! error TS2339: Property 'setter' does not exist on type 'Omit<this, "normal" | "getter" | "setter" | "method">'.
71+
rest4.setter;
72+
~~~~~~
73+
!!! error TS2339: Property 'setter' does not exist on type '{}'.
74+
75+
rest1.method;
76+
~~~~~~
77+
!!! error TS2339: Property 'method' does not exist on type 'Omit<this, "getter" | "setter" | "method">'.
78+
rest2.method;
79+
~~~~~~
80+
!!! error TS2339: Property 'method' does not exist on type '{ normal: string; }'.
81+
rest3.method;
82+
~~~~~~
83+
!!! error TS2339: Property 'method' does not exist on type 'Omit<this, "normal" | "getter" | "setter" | "method">'.
84+
rest4.method;
85+
~~~~~~
86+
!!! error TS2339: Property 'method' does not exist on type '{}'.
6187
}
6288
}
6389

6490
function destructure<T extends A>(x: T) {
6591
const { ...rest1 } = x;
6692
const { ...rest2 } = x as A;
67-
const { foo: _f1, ...rest3 } = x;
68-
const { foo: _f2, ...rest4 } = x as A;
93+
const { normal: _1, ...rest3 } = x;
94+
const { normal: _2, ...rest4 } = x as A;
95+
96+
rest1.getter;
97+
~~~~~~
98+
!!! error TS2339: Property 'getter' does not exist on type 'Omit<T, "getter" | "setter" | "method">'.
99+
rest2.getter;
100+
~~~~~~
101+
!!! error TS2339: Property 'getter' does not exist on type '{ normal: string; }'.
102+
rest3.getter;
103+
~~~~~~
104+
!!! error TS2339: Property 'getter' does not exist on type 'Omit<T, "normal" | "getter" | "setter" | "method">'.
105+
rest4.getter;
106+
~~~~~~
107+
!!! error TS2339: Property 'getter' does not exist on type '{}'.
69108

70-
rest1.bar;
71-
~~~
72-
!!! error TS2339: Property 'bar' does not exist on type 'Omit<T, "bar" | "func">'.
73-
rest2.bar;
74-
~~~
75-
!!! error TS2339: Property 'bar' does not exist on type '{ foo: string; }'.
76-
rest3.bar;
77-
~~~
78-
!!! error TS2339: Property 'bar' does not exist on type 'Omit<T, "foo" | "bar" | "func">'.
79-
rest4.bar;
80-
~~~
81-
!!! error TS2339: Property 'bar' does not exist on type '{}'.
109+
rest1.setter;
110+
~~~~~~
111+
!!! error TS2339: Property 'setter' does not exist on type 'Omit<T, "getter" | "setter" | "method">'.
112+
rest2.setter;
113+
~~~~~~
114+
!!! error TS2339: Property 'setter' does not exist on type '{ normal: string; }'.
115+
rest3.setter;
116+
~~~~~~
117+
!!! error TS2339: Property 'setter' does not exist on type 'Omit<T, "normal" | "getter" | "setter" | "method">'.
118+
rest4.setter;
119+
~~~~~~
120+
!!! error TS2339: Property 'setter' does not exist on type '{}'.
82121

83-
rest1.func;
84-
~~~~
85-
!!! error TS2339: Property 'func' does not exist on type 'Omit<T, "bar" | "func">'.
86-
rest2.func;
87-
~~~~
88-
!!! error TS2339: Property 'func' does not exist on type '{ foo: string; }'.
89-
rest3.func;
90-
~~~~
91-
!!! error TS2339: Property 'func' does not exist on type 'Omit<T, "foo" | "bar" | "func">'.
92-
rest4.func;
93-
~~~~
94-
!!! error TS2339: Property 'func' does not exist on type '{}'.
122+
rest1.method;
123+
~~~~~~
124+
!!! error TS2339: Property 'method' does not exist on type 'Omit<T, "getter" | "setter" | "method">'.
125+
rest2.method;
126+
~~~~~~
127+
!!! error TS2339: Property 'method' does not exist on type '{ normal: string; }'.
128+
rest3.method;
129+
~~~~~~
130+
!!! error TS2339: Property 'method' does not exist on type 'Omit<T, "normal" | "getter" | "setter" | "method">'.
131+
rest4.method;
132+
~~~~~~
133+
!!! error TS2339: Property 'method' does not exist on type '{}'.
95134
}
96135

Original file line numberDiff line numberDiff line change
@@ -1,44 +1,56 @@
11
//// [destructuringUnspreadableIntoRest.ts]
22
class A {
3-
constructor(public foo: string) {}
3+
constructor(public normal: string) {}
44

5-
get bar(): number {
5+
get getter(): number {
66
return 1;
77
}
88

9-
func() {
9+
set setter(_v: number) {}
10+
11+
method() {
1012
const { ...rest1 } = this;
1113
const { ...rest2 } = this as A;
12-
const { foo: _f1, ...rest3 } = this;
13-
const { foo: _f2, ...rest4 } = this as A;
14+
const { normal: _1, ...rest3 } = this;
15+
const { normal: _2, ...rest4 } = this as A;
16+
17+
rest1.getter;
18+
rest2.getter;
19+
rest3.getter;
20+
rest4.getter;
1421

15-
rest1.bar;
16-
rest2.bar;
17-
rest3.bar;
18-
rest4.bar;
22+
rest1.setter;
23+
rest2.setter;
24+
rest3.setter;
25+
rest4.setter;
1926

20-
rest1.func;
21-
rest2.func;
22-
rest3.func;
23-
rest4.func;
27+
rest1.method;
28+
rest2.method;
29+
rest3.method;
30+
rest4.method;
2431
}
2532
}
2633

2734
function destructure<T extends A>(x: T) {
2835
const { ...rest1 } = x;
2936
const { ...rest2 } = x as A;
30-
const { foo: _f1, ...rest3 } = x;
31-
const { foo: _f2, ...rest4 } = x as A;
37+
const { normal: _1, ...rest3 } = x;
38+
const { normal: _2, ...rest4 } = x as A;
39+
40+
rest1.getter;
41+
rest2.getter;
42+
rest3.getter;
43+
rest4.getter;
3244

33-
rest1.bar;
34-
rest2.bar;
35-
rest3.bar;
36-
rest4.bar;
45+
rest1.setter;
46+
rest2.setter;
47+
rest3.setter;
48+
rest4.setter;
3749

38-
rest1.func;
39-
rest2.func;
40-
rest3.func;
41-
rest4.func;
50+
rest1.method;
51+
rest2.method;
52+
rest3.method;
53+
rest4.method;
4254
}
4355

4456

@@ -55,43 +67,56 @@ var __rest = (this && this.__rest) || function (s, e) {
5567
return t;
5668
};
5769
var A = /** @class */ (function () {
58-
function A(foo) {
59-
this.foo = foo;
70+
function A(normal) {
71+
this.normal = normal;
6072
}
61-
Object.defineProperty(A.prototype, "bar", {
73+
Object.defineProperty(A.prototype, "getter", {
6274
get: function () {
6375
return 1;
6476
},
6577
enumerable: false,
6678
configurable: true
6779
});
68-
A.prototype.func = function () {
80+
Object.defineProperty(A.prototype, "setter", {
81+
set: function (_v) { },
82+
enumerable: false,
83+
configurable: true
84+
});
85+
A.prototype.method = function () {
6986
var rest1 = __rest(this, []);
7087
var rest2 = __rest(this, []);
71-
var _a = this, _f1 = _a.foo, rest3 = __rest(_a, ["foo"]);
72-
var _b = this, _f2 = _b.foo, rest4 = __rest(_b, ["foo"]);
73-
rest1.bar;
74-
rest2.bar;
75-
rest3.bar;
76-
rest4.bar;
77-
rest1.func;
78-
rest2.func;
79-
rest3.func;
80-
rest4.func;
88+
var _a = this, _1 = _a.normal, rest3 = __rest(_a, ["normal"]);
89+
var _b = this, _2 = _b.normal, rest4 = __rest(_b, ["normal"]);
90+
rest1.getter;
91+
rest2.getter;
92+
rest3.getter;
93+
rest4.getter;
94+
rest1.setter;
95+
rest2.setter;
96+
rest3.setter;
97+
rest4.setter;
98+
rest1.method;
99+
rest2.method;
100+
rest3.method;
101+
rest4.method;
81102
};
82103
return A;
83104
}());
84105
function destructure(x) {
85106
var rest1 = __rest(x, []);
86107
var rest2 = __rest(x, []);
87-
var _f1 = x.foo, rest3 = __rest(x, ["foo"]);
88-
var _a = x, _f2 = _a.foo, rest4 = __rest(_a, ["foo"]);
89-
rest1.bar;
90-
rest2.bar;
91-
rest3.bar;
92-
rest4.bar;
93-
rest1.func;
94-
rest2.func;
95-
rest3.func;
96-
rest4.func;
108+
var _1 = x.normal, rest3 = __rest(x, ["normal"]);
109+
var _a = x, _2 = _a.normal, rest4 = __rest(_a, ["normal"]);
110+
rest1.getter;
111+
rest2.getter;
112+
rest3.getter;
113+
rest4.getter;
114+
rest1.setter;
115+
rest2.setter;
116+
rest3.setter;
117+
rest4.setter;
118+
rest1.method;
119+
rest2.method;
120+
rest3.method;
121+
rest4.method;
97122
}

0 commit comments

Comments
 (0)