Skip to content

Commit

Permalink
Excise well-known symbol ignoring code in index signature handling
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Mar 3, 2021
1 parent ff3890f commit 05f63f6
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 15 deletions.
9 changes: 1 addition & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36442,13 +36442,6 @@ namespace ts {
if (indexInfos) {
forEach(getPropertiesOfObjectType(type), prop => {
const propType = getTypeOfSymbol(prop);
// TODO: Well known symbols should _probably_ be subject to a symbol indexer, but unfortunately they have no associated literal
// type right now, so they're very difficult to check/flow. They're on the chopping block for removal thanks to advancements,
// and other issues though, so it's probably OK to just let their removal and simultaneous replacement with `unique symbol`s
// fix this.
if (isKnownSymbol(prop)) {
return;
}
checkIndexConstraintForProperty(prop, getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique, /*retainNonpublicNames*/ true), propType, type, declaredIndexers);
});

Expand Down Expand Up @@ -36533,7 +36526,7 @@ namespace ts {
let errorNode: Node | undefined;
if (propDeclaration && name &&
(propDeclaration.kind === SyntaxKind.BinaryExpression ||
name.kind === SyntaxKind.ComputedPropertyName ||
(name.kind === SyntaxKind.ComputedPropertyName && name.parent.parent === containingType.symbol.valueDeclaration) ||
prop.parent === containingType.symbol)) {
errorNode = propDeclaration;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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'.
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'.
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'.


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

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

class D extends C {
// No error when the indexer is in a class more derived than the computed property
[s: string]: Foo2;
~~~~~~~~~~~~~~~~~~
!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
set ["set1"](p: Foo) { }
~~~~~~~~
!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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'.
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'.
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'.


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

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

class D extends C {
// No error when the indexer is in a class more derived than the computed property
[s: string]: Foo2;
~~~~~~~~~~~~~~~~~~
!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
set ["set1"](p: Foo) { }
~~~~~~~~
!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'.
Expand Down
14 changes: 14 additions & 0 deletions tests/baselines/reference/symbolProperty17.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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'.


==== tests/cases/conformance/es6/Symbols/symbolProperty17.ts (1 errors) ====
interface I {
[Symbol.iterator]: number;
~~~~~~~~~~~~~~~~~
!!! error TS2411: Property '[Symbol.iterator]' of type 'number' is not assignable to 'symbol' index type 'string'.
[s: symbol]: string;
"__@iterator": string;
}

var i: I;
var it = i[Symbol.iterator];
12 changes: 12 additions & 0 deletions tests/baselines/reference/symbolProperty30.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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; }'.


==== tests/cases/conformance/es6/Symbols/symbolProperty30.ts (1 errors) ====
class C1 {
[Symbol.toStringTag]() {
~~~~~~~~~~~~~~~~~~~~
!!! error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'.
return { x: "" };
}
[s: symbol]: () => { x: number };
}
14 changes: 14 additions & 0 deletions tests/baselines/reference/symbolProperty32.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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; }'.


==== tests/cases/conformance/es6/Symbols/symbolProperty32.ts (1 errors) ====
class C1 {
[Symbol.toStringTag]() {
return { x: "" };
}
}
class C2 extends C1 {
[s: symbol]: () => { x: number };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'.
}
5 changes: 4 additions & 1 deletion tests/baselines/reference/symbolProperty34.errors.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
tests/cases/conformance/es6/Symbols/symbolProperty34.ts(1,18): error TS2449: Class 'C2' used before its declaration.
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; }'.


==== tests/cases/conformance/es6/Symbols/symbolProperty34.ts (1 errors) ====
==== tests/cases/conformance/es6/Symbols/symbolProperty34.ts (2 errors) ====
class C1 extends C2 {
~~
!!! error TS2449: Class 'C2' used before its declaration.
!!! related TS2728 tests/cases/conformance/es6/Symbols/symbolProperty34.ts:6:7: 'C2' is declared here.
[Symbol.toStringTag]() {
~~~~~~~~~~~~~~~~~~~~
!!! error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'.
return { x: "" };
}
}
Expand Down

0 comments on commit 05f63f6

Please sign in to comment.