Skip to content

Commit 05f63f6

Browse files
committed
Excise well-known symbol ignoring code in index signature handling
1 parent ff3890f commit 05f63f6

7 files changed

+51
-15
lines changed

Diff for: src/compiler/checker.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -36442,13 +36442,6 @@ namespace ts {
3644236442
if (indexInfos) {
3644336443
forEach(getPropertiesOfObjectType(type), prop => {
3644436444
const propType = getTypeOfSymbol(prop);
36445-
// TODO: Well known symbols should _probably_ be subject to a symbol indexer, but unfortunately they have no associated literal
36446-
// type right now, so they're very difficult to check/flow. They're on the chopping block for removal thanks to advancements,
36447-
// and other issues though, so it's probably OK to just let their removal and simultaneous replacement with `unique symbol`s
36448-
// fix this.
36449-
if (isKnownSymbol(prop)) {
36450-
return;
36451-
}
3645236445
checkIndexConstraintForProperty(prop, getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique, /*retainNonpublicNames*/ true), propType, type, declaredIndexers);
3645336446
});
3645436447

@@ -36533,7 +36526,7 @@ namespace ts {
3653336526
let errorNode: Node | undefined;
3653436527
if (propDeclaration && name &&
3653536528
(propDeclaration.kind === SyntaxKind.BinaryExpression ||
36536-
name.kind === SyntaxKind.ComputedPropertyName ||
36529+
(name.kind === SyntaxKind.ComputedPropertyName && name.parent.parent === containingType.symbol.valueDeclaration) ||
3653736530
prop.parent === containingType.symbol)) {
3653836531
errorNode = propDeclaration;
3653936532
}

Diff for: tests/baselines/reference/computedPropertyNames45_ES5.errors.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(5,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
1+
tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(10,5): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
22
tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(11,9): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
33

44

@@ -8,13 +8,13 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(11
88

99
class C {
1010
get ["get1"]() { return new Foo }
11-
~~~~~~~~
12-
!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
1311
}
1412

1513
class D extends C {
1614
// No error when the indexer is in a class more derived than the computed property
1715
[s: string]: Foo2;
16+
~~~~~~~~~~~~~~~~~~
17+
!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
1818
set ["set1"](p: Foo) { }
1919
~~~~~~~~
2020
!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.

Diff for: tests/baselines/reference/computedPropertyNames45_ES6.errors.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(5,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
1+
tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(10,5): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
22
tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(11,9): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
33

44

@@ -8,13 +8,13 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(11
88

99
class C {
1010
get ["get1"]() { return new Foo }
11-
~~~~~~~~
12-
!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
1311
}
1412

1513
class D extends C {
1614
// No error when the indexer is in a class more derived than the computed property
1715
[s: string]: Foo2;
16+
~~~~~~~~~~~~~~~~~~
17+
!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
1818
set ["set1"](p: Foo) { }
1919
~~~~~~~~
2020
!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests/cases/conformance/es6/Symbols/symbolProperty17.ts(2,5): error TS2411: Property '[Symbol.iterator]' of type 'number' is not assignable to 'symbol' index type 'string'.
2+
3+
4+
==== tests/cases/conformance/es6/Symbols/symbolProperty17.ts (1 errors) ====
5+
interface I {
6+
[Symbol.iterator]: number;
7+
~~~~~~~~~~~~~~~~~
8+
!!! error TS2411: Property '[Symbol.iterator]' of type 'number' is not assignable to 'symbol' index type 'string'.
9+
[s: symbol]: string;
10+
"__@iterator": string;
11+
}
12+
13+
var i: I;
14+
var it = i[Symbol.iterator];
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tests/cases/conformance/es6/Symbols/symbolProperty30.ts(2,5): error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'.
2+
3+
4+
==== tests/cases/conformance/es6/Symbols/symbolProperty30.ts (1 errors) ====
5+
class C1 {
6+
[Symbol.toStringTag]() {
7+
~~~~~~~~~~~~~~~~~~~~
8+
!!! error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'.
9+
return { x: "" };
10+
}
11+
[s: symbol]: () => { x: number };
12+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tests/cases/conformance/es6/Symbols/symbolProperty32.ts(7,5): error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'.
2+
3+
4+
==== tests/cases/conformance/es6/Symbols/symbolProperty32.ts (1 errors) ====
5+
class C1 {
6+
[Symbol.toStringTag]() {
7+
return { x: "" };
8+
}
9+
}
10+
class C2 extends C1 {
11+
[s: symbol]: () => { x: number };
12+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13+
!!! error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'.
14+
}

Diff for: tests/baselines/reference/symbolProperty34.errors.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
tests/cases/conformance/es6/Symbols/symbolProperty34.ts(1,18): error TS2449: Class 'C2' used before its declaration.
2+
tests/cases/conformance/es6/Symbols/symbolProperty34.ts(2,5): error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'.
23

34

4-
==== tests/cases/conformance/es6/Symbols/symbolProperty34.ts (1 errors) ====
5+
==== tests/cases/conformance/es6/Symbols/symbolProperty34.ts (2 errors) ====
56
class C1 extends C2 {
67
~~
78
!!! error TS2449: Class 'C2' used before its declaration.
89
!!! related TS2728 tests/cases/conformance/es6/Symbols/symbolProperty34.ts:6:7: 'C2' is declared here.
910
[Symbol.toStringTag]() {
11+
~~~~~~~~~~~~~~~~~~~~
12+
!!! error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'.
1013
return { x: "" };
1114
}
1215
}

0 commit comments

Comments
 (0)