Skip to content

Commit 241a6c9

Browse files
authored
fix(55168): Computed properties do not respect setter signatures (#55178)
1 parent e25abe3 commit 241a6c9

4 files changed

+229
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [tests/cases/compiler/computedPropertiesWithSetterAssignment.ts] ////
2+
3+
//// [a.ts]
4+
const k = Symbol();
5+
6+
const enum Props {
7+
k = 'k',
8+
}
9+
10+
interface Foo {
11+
get k(): Set<string>;
12+
set k(v: Iterable<string>);
13+
14+
get [k](): Set<string>;
15+
set [k](v: Iterable<string>);
16+
}
17+
18+
declare const foo: Foo;
19+
20+
foo.k = ['foo'];
21+
foo['k'] = ['foo'];
22+
foo[Props.k] = ['foo'];
23+
foo[k] = ['foo'];
24+
25+
26+
//// [a.js]
27+
"use strict";
28+
const k = Symbol();
29+
foo.k = ['foo'];
30+
foo['k'] = ['foo'];
31+
foo["k" /* Props.k */] = ['foo'];
32+
foo[k] = ['foo'];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//// [tests/cases/compiler/computedPropertiesWithSetterAssignment.ts] ////
2+
3+
=== /a.ts ===
4+
const k = Symbol();
5+
>k : Symbol(k, Decl(a.ts, 0, 5))
6+
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --))
7+
8+
const enum Props {
9+
>Props : Symbol(Props, Decl(a.ts, 0, 19))
10+
11+
k = 'k',
12+
>k : Symbol(Props.k, Decl(a.ts, 2, 18))
13+
}
14+
15+
interface Foo {
16+
>Foo : Symbol(Foo, Decl(a.ts, 4, 1))
17+
18+
get k(): Set<string>;
19+
>k : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25))
20+
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --))
21+
22+
set k(v: Iterable<string>);
23+
>k : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25))
24+
>v : Symbol(v, Decl(a.ts, 8, 10))
25+
>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --))
26+
27+
get [k](): Set<string>;
28+
>[k] : Symbol(Foo[k], Decl(a.ts, 8, 31), Decl(a.ts, 10, 27))
29+
>k : Symbol(k, Decl(a.ts, 0, 5))
30+
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --))
31+
32+
set [k](v: Iterable<string>);
33+
>[k] : Symbol(Foo[k], Decl(a.ts, 8, 31), Decl(a.ts, 10, 27))
34+
>k : Symbol(k, Decl(a.ts, 0, 5))
35+
>v : Symbol(v, Decl(a.ts, 11, 12))
36+
>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --))
37+
}
38+
39+
declare const foo: Foo;
40+
>foo : Symbol(foo, Decl(a.ts, 14, 13))
41+
>Foo : Symbol(Foo, Decl(a.ts, 4, 1))
42+
43+
foo.k = ['foo'];
44+
>foo.k : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25))
45+
>foo : Symbol(foo, Decl(a.ts, 14, 13))
46+
>k : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25))
47+
48+
foo['k'] = ['foo'];
49+
>foo : Symbol(foo, Decl(a.ts, 14, 13))
50+
>'k' : Symbol(Foo.k, Decl(a.ts, 6, 15), Decl(a.ts, 7, 25))
51+
52+
foo[Props.k] = ['foo'];
53+
>foo : Symbol(foo, Decl(a.ts, 14, 13))
54+
>Props.k : Symbol(Props.k, Decl(a.ts, 2, 18))
55+
>Props : Symbol(Props, Decl(a.ts, 0, 19))
56+
>k : Symbol(Props.k, Decl(a.ts, 2, 18))
57+
58+
foo[k] = ['foo'];
59+
>foo : Symbol(foo, Decl(a.ts, 14, 13))
60+
>k : Symbol(k, Decl(a.ts, 0, 5))
61+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//// [tests/cases/compiler/computedPropertiesWithSetterAssignment.ts] ////
2+
3+
=== /a.ts ===
4+
const k = Symbol();
5+
>k : unique symbol
6+
> : ^^^^^^^^^^^^^
7+
>Symbol() : unique symbol
8+
> : ^^^^^^^^^^^^^
9+
>Symbol : SymbolConstructor
10+
> : ^^^^^^^^^^^^^^^^^
11+
12+
const enum Props {
13+
>Props : Props
14+
> : ^^^^^
15+
16+
k = 'k',
17+
>k : Props.k
18+
> : ^^^^^^^
19+
>'k' : "k"
20+
> : ^^^
21+
}
22+
23+
interface Foo {
24+
get k(): Set<string>;
25+
>k : Set<string>
26+
> : ^^^^^^^^^^^
27+
28+
set k(v: Iterable<string>);
29+
>k : Set<string>
30+
> : ^^^^^^^^^^^
31+
>v : Iterable<string>
32+
> : ^^^^^^^^^^^^^^^^
33+
34+
get [k](): Set<string>;
35+
>[k] : Set<string>
36+
> : ^^^^^^^^^^^
37+
>k : unique symbol
38+
> : ^^^^^^^^^^^^^
39+
40+
set [k](v: Iterable<string>);
41+
>[k] : Set<string>
42+
> : ^^^^^^^^^^^
43+
>k : unique symbol
44+
> : ^^^^^^^^^^^^^
45+
>v : Iterable<string>
46+
> : ^^^^^^^^^^^^^^^^
47+
}
48+
49+
declare const foo: Foo;
50+
>foo : Foo
51+
> : ^^^
52+
53+
foo.k = ['foo'];
54+
>foo.k = ['foo'] : string[]
55+
> : ^^^^^^^^
56+
>foo.k : Iterable<string>
57+
> : ^^^^^^^^^^^^^^^^
58+
>foo : Foo
59+
> : ^^^
60+
>k : Iterable<string>
61+
> : ^^^^^^^^^^^^^^^^
62+
>['foo'] : string[]
63+
> : ^^^^^^^^
64+
>'foo' : "foo"
65+
> : ^^^^^
66+
67+
foo['k'] = ['foo'];
68+
>foo['k'] = ['foo'] : string[]
69+
> : ^^^^^^^^
70+
>foo['k'] : Iterable<string>
71+
> : ^^^^^^^^^^^^^^^^
72+
>foo : Foo
73+
> : ^^^
74+
>'k' : "k"
75+
> : ^^^
76+
>['foo'] : string[]
77+
> : ^^^^^^^^
78+
>'foo' : "foo"
79+
> : ^^^^^
80+
81+
foo[Props.k] = ['foo'];
82+
>foo[Props.k] = ['foo'] : string[]
83+
> : ^^^^^^^^
84+
>foo[Props.k] : Iterable<string>
85+
> : ^^^^^^^^^^^^^^^^
86+
>foo : Foo
87+
> : ^^^
88+
>Props.k : Props
89+
> : ^^^^^
90+
>Props : typeof Props
91+
> : ^^^^^^^^^^^^
92+
>k : Props
93+
> : ^^^^^
94+
>['foo'] : string[]
95+
> : ^^^^^^^^
96+
>'foo' : "foo"
97+
> : ^^^^^
98+
99+
foo[k] = ['foo'];
100+
>foo[k] = ['foo'] : string[]
101+
> : ^^^^^^^^
102+
>foo[k] : Iterable<string>
103+
> : ^^^^^^^^^^^^^^^^
104+
>foo : Foo
105+
> : ^^^
106+
>k : unique symbol
107+
> : ^^^^^^^^^^^^^
108+
>['foo'] : string[]
109+
> : ^^^^^^^^
110+
>'foo' : "foo"
111+
> : ^^^^^
112+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// @target: esnext
2+
// @strict: true
3+
// @filename: /a.ts
4+
5+
const k = Symbol();
6+
7+
const enum Props {
8+
k = 'k',
9+
}
10+
11+
interface Foo {
12+
get k(): Set<string>;
13+
set k(v: Iterable<string>);
14+
15+
get [k](): Set<string>;
16+
set [k](v: Iterable<string>);
17+
}
18+
19+
declare const foo: Foo;
20+
21+
foo.k = ['foo'];
22+
foo['k'] = ['foo'];
23+
foo[Props.k] = ['foo'];
24+
foo[k] = ['foo'];

0 commit comments

Comments
 (0)