Skip to content

Commit 7a89c96

Browse files
authored
Merge pull request #21217 from Microsoft/fix20146
Symbol-named properties do not need to align with string indexer type
2 parents dcc5c32 + 6c98277 commit 7a89c96

File tree

5 files changed

+146
-1
lines changed

5 files changed

+146
-1
lines changed

src/compiler/checker.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -22298,7 +22298,8 @@ namespace ts {
2229822298
indexType: Type,
2229922299
indexKind: IndexKind): void {
2230022300

22301-
if (!indexType) {
22301+
// ESSymbol properties apply to neither string nor numeric indexers.
22302+
if (!indexType || isKnownSymbol(prop)) {
2230222303
return;
2230322304
}
2230422305

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [symbolProperty60.ts]
2+
// https://github.com/Microsoft/TypeScript/issues/20146
3+
interface I1 {
4+
[Symbol.toStringTag]: string;
5+
[key: string]: number;
6+
}
7+
8+
interface I2 {
9+
[Symbol.toStringTag]: string;
10+
[key: number]: boolean;
11+
}
12+
13+
declare const mySymbol: unique symbol;
14+
15+
interface I3 {
16+
[mySymbol]: string;
17+
[key: string]: number;
18+
}
19+
20+
interface I4 {
21+
[mySymbol]: string;
22+
[key: number]: boolean;
23+
}
24+
25+
//// [symbolProperty60.js]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
=== tests/cases/conformance/es6/Symbols/symbolProperty60.ts ===
2+
// https://github.com/Microsoft/TypeScript/issues/20146
3+
interface I1 {
4+
>I1 : Symbol(I1, Decl(symbolProperty60.ts, 0, 0))
5+
6+
[Symbol.toStringTag]: string;
7+
>Symbol.toStringTag : Symbol(SymbolConstructor.toStringTag, Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
8+
>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --))
9+
>toStringTag : Symbol(SymbolConstructor.toStringTag, Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
10+
11+
[key: string]: number;
12+
>key : Symbol(key, Decl(symbolProperty60.ts, 3, 5))
13+
}
14+
15+
interface I2 {
16+
>I2 : Symbol(I2, Decl(symbolProperty60.ts, 4, 1))
17+
18+
[Symbol.toStringTag]: string;
19+
>Symbol.toStringTag : Symbol(SymbolConstructor.toStringTag, Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
20+
>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --))
21+
>toStringTag : Symbol(SymbolConstructor.toStringTag, Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
22+
23+
[key: number]: boolean;
24+
>key : Symbol(key, Decl(symbolProperty60.ts, 8, 5))
25+
}
26+
27+
declare const mySymbol: unique symbol;
28+
>mySymbol : Symbol(mySymbol, Decl(symbolProperty60.ts, 11, 13))
29+
30+
interface I3 {
31+
>I3 : Symbol(I3, Decl(symbolProperty60.ts, 11, 38))
32+
33+
[mySymbol]: string;
34+
>mySymbol : Symbol(mySymbol, Decl(symbolProperty60.ts, 11, 13))
35+
36+
[key: string]: number;
37+
>key : Symbol(key, Decl(symbolProperty60.ts, 15, 5))
38+
}
39+
40+
interface I4 {
41+
>I4 : Symbol(I4, Decl(symbolProperty60.ts, 16, 1))
42+
43+
[mySymbol]: string;
44+
>mySymbol : Symbol(mySymbol, Decl(symbolProperty60.ts, 11, 13))
45+
46+
[key: number]: boolean;
47+
>key : Symbol(key, Decl(symbolProperty60.ts, 20, 5))
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
=== tests/cases/conformance/es6/Symbols/symbolProperty60.ts ===
2+
// https://github.com/Microsoft/TypeScript/issues/20146
3+
interface I1 {
4+
>I1 : I1
5+
6+
[Symbol.toStringTag]: string;
7+
>Symbol.toStringTag : symbol
8+
>Symbol : SymbolConstructor
9+
>toStringTag : symbol
10+
11+
[key: string]: number;
12+
>key : string
13+
}
14+
15+
interface I2 {
16+
>I2 : I2
17+
18+
[Symbol.toStringTag]: string;
19+
>Symbol.toStringTag : symbol
20+
>Symbol : SymbolConstructor
21+
>toStringTag : symbol
22+
23+
[key: number]: boolean;
24+
>key : number
25+
}
26+
27+
declare const mySymbol: unique symbol;
28+
>mySymbol : unique symbol
29+
30+
interface I3 {
31+
>I3 : I3
32+
33+
[mySymbol]: string;
34+
>mySymbol : unique symbol
35+
36+
[key: string]: number;
37+
>key : string
38+
}
39+
40+
interface I4 {
41+
>I4 : I4
42+
43+
[mySymbol]: string;
44+
>mySymbol : unique symbol
45+
46+
[key: number]: boolean;
47+
>key : number
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @target: es2015
2+
// https://github.com/Microsoft/TypeScript/issues/20146
3+
interface I1 {
4+
[Symbol.toStringTag]: string;
5+
[key: string]: number;
6+
}
7+
8+
interface I2 {
9+
[Symbol.toStringTag]: string;
10+
[key: number]: boolean;
11+
}
12+
13+
declare const mySymbol: unique symbol;
14+
15+
interface I3 {
16+
[mySymbol]: string;
17+
[key: string]: number;
18+
}
19+
20+
interface I4 {
21+
[mySymbol]: string;
22+
[key: number]: boolean;
23+
}

0 commit comments

Comments
 (0)