From 5b0eea48e93aa073ea5322a83c8a4d29e6a166a7 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 27 Jul 2022 15:31:45 -0700 Subject: [PATCH] Report error only on local declaration with additional related information (#49746) * Add test where the errors are reported in different file Test for #49739 * Report error only on local declaration with additional related information Fixes #49739 * Handle existing tests --- src/compiler/checker.ts | 11 ++- .../computedPropertyNames45_ES5.errors.txt | 7 +- .../computedPropertyNames45_ES6.errors.txt | 7 +- .../indexSignatureInOtherFile.errors.txt | 49 +++++++++++ .../reference/indexSignatureInOtherFile.js | 46 ++++++++++ .../indexSignatureInOtherFile.symbols | 87 +++++++++++++++++++ .../reference/indexSignatureInOtherFile.types | 71 +++++++++++++++ .../indexSignatureInOtherFile1.errors.txt | 48 ++++++++++ .../reference/indexSignatureInOtherFile1.js | 45 ++++++++++ .../indexSignatureInOtherFile1.symbols | 86 ++++++++++++++++++ .../indexSignatureInOtherFile1.types | 70 +++++++++++++++ .../reference/symbolProperty32.errors.txt | 7 +- .../compiler/indexSignatureInOtherFile.ts | 39 +++++++++ .../compiler/indexSignatureInOtherFile1.ts | 39 +++++++++ 14 files changed, 600 insertions(+), 12 deletions(-) create mode 100644 tests/baselines/reference/indexSignatureInOtherFile.errors.txt create mode 100644 tests/baselines/reference/indexSignatureInOtherFile.js create mode 100644 tests/baselines/reference/indexSignatureInOtherFile.symbols create mode 100644 tests/baselines/reference/indexSignatureInOtherFile.types create mode 100644 tests/baselines/reference/indexSignatureInOtherFile1.errors.txt create mode 100644 tests/baselines/reference/indexSignatureInOtherFile1.js create mode 100644 tests/baselines/reference/indexSignatureInOtherFile1.symbols create mode 100644 tests/baselines/reference/indexSignatureInOtherFile1.types create mode 100644 tests/cases/compiler/indexSignatureInOtherFile.ts create mode 100644 tests/cases/compiler/indexSignatureInOtherFile1.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e3dbc1b0efc..d1c202c8bde 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39552,8 +39552,9 @@ namespace ts { } const indexInfos = getApplicableIndexInfos(type, propNameType); const interfaceDeclaration = getObjectFlags(type) & ObjectFlags.Interface ? getDeclarationOfKind(type.symbol, SyntaxKind.InterfaceDeclaration) : undefined; - const localPropDeclaration = declaration && declaration.kind === SyntaxKind.BinaryExpression || - name && name.kind === SyntaxKind.ComputedPropertyName || getParentOfSymbol(prop) === type.symbol ? declaration : undefined; + const propDeclaration = declaration && declaration.kind === SyntaxKind.BinaryExpression || + name && name.kind === SyntaxKind.ComputedPropertyName ? declaration : undefined; + const localPropDeclaration = getParentOfSymbol(prop) === type.symbol ? declaration : undefined; for (const info of indexInfos) { const localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined; // We check only when (a) the property is declared in the containing type, or (b) the applicable index signature is declared @@ -39562,8 +39563,12 @@ namespace ts { const errorNode = localPropDeclaration || localIndexDeclaration || (interfaceDeclaration && !some(getBaseTypes(type as InterfaceType), base => !!getPropertyOfObjectType(base, prop.escapedName) && !!getIndexTypeOfType(base, info.keyType)) ? interfaceDeclaration : undefined); if (errorNode && !isTypeAssignableTo(propType, info.type)) { - error(errorNode, Diagnostics.Property_0_of_type_1_is_not_assignable_to_2_index_type_3, + const diagnostic = createError(errorNode, Diagnostics.Property_0_of_type_1_is_not_assignable_to_2_index_type_3, symbolToString(prop), typeToString(propType), typeToString(info.keyType), typeToString(info.type)); + if (propDeclaration && errorNode !== propDeclaration) { + addRelatedInfo(diagnostic, createDiagnosticForNode(propDeclaration, Diagnostics._0_is_declared_here, symbolToString(prop))); + } + diagnostics.add(diagnostic); } } } diff --git a/tests/baselines/reference/computedPropertyNames45_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames45_ES5.errors.txt index dca0d5f5a16..4ee1e6ad441 100644 --- a/tests/baselines/reference/computedPropertyNames45_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames45_ES5.errors.txt @@ -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'. @@ -8,13 +8,14 @@ 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'. +!!! related TS2728 tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts:5:9: '["get1"]' is declared here. set ["set1"](p: Foo) { } ~~~~~~~~ !!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. diff --git a/tests/baselines/reference/computedPropertyNames45_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames45_ES6.errors.txt index 5bd2d5caa4a..d25826ef8fb 100644 --- a/tests/baselines/reference/computedPropertyNames45_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames45_ES6.errors.txt @@ -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'. @@ -8,13 +8,14 @@ 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'. +!!! related TS2728 tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts:5:9: '["get1"]' is declared here. set ["set1"](p: Foo) { } ~~~~~~~~ !!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. diff --git a/tests/baselines/reference/indexSignatureInOtherFile.errors.txt b/tests/baselines/reference/indexSignatureInOtherFile.errors.txt new file mode 100644 index 00000000000..d6c04031680 --- /dev/null +++ b/tests/baselines/reference/indexSignatureInOtherFile.errors.txt @@ -0,0 +1,49 @@ +tests/cases/compiler/index.ts(2,3): error TS2411: Property '[Symbol.iterator]' of type '() => IterableIterator' is not assignable to 'symbol' index type 'string'. +tests/cases/compiler/index.ts(2,3): error TS2411: Property '[Symbol.unscopables]' of type '() => { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }' is not assignable to 'symbol' index type 'string'. + + +==== tests/cases/compiler/index.ts (2 errors) ==== + class Test extends Array1 { + [key: symbol]: string + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '[Symbol.iterator]' of type '() => IterableIterator' is not assignable to 'symbol' index type 'string'. +!!! related TS2728 tests/cases/compiler/other.ts:14:3: '[Symbol.iterator]' is declared here. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '[Symbol.unscopables]' of type '() => { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }' is not assignable to 'symbol' index type 'string'. +!!! related TS2728 tests/cases/compiler/other.ts:23:3: '[Symbol.unscopables]' is declared here. + } + +==== tests/cases/compiler/other.ts (0 errors) ==== + interface Array1 { + length: number; + [n: number]: T; + } + + interface ArrayConstructor1 { + new(arrayLength?: number): Array1; + } + + declare var Array1: ArrayConstructor1; + + // iterable.d.ts + interface Array1 { + [Symbol.iterator](): IterableIterator; + } + + // symbol.wellknown.d.ts + interface Array1 { + /** + * Returns an object whose properties have the value 'true' + * when they will be absent when used in a 'with' statement. + */ + [Symbol.unscopables](): { + copyWithin: boolean; + entries: boolean; + fill: boolean; + find: boolean; + findIndex: boolean; + keys: boolean; + values: boolean; + }; + } + \ No newline at end of file diff --git a/tests/baselines/reference/indexSignatureInOtherFile.js b/tests/baselines/reference/indexSignatureInOtherFile.js new file mode 100644 index 00000000000..68c14ca853e --- /dev/null +++ b/tests/baselines/reference/indexSignatureInOtherFile.js @@ -0,0 +1,46 @@ +//// [tests/cases/compiler/indexSignatureInOtherFile.ts] //// + +//// [index.ts] +class Test extends Array1 { + [key: symbol]: string +} + +//// [other.ts] +interface Array1 { + length: number; + [n: number]: T; +} + +interface ArrayConstructor1 { + new(arrayLength?: number): Array1; +} + +declare var Array1: ArrayConstructor1; + +// iterable.d.ts +interface Array1 { + [Symbol.iterator](): IterableIterator; +} + +// symbol.wellknown.d.ts +interface Array1 { + /** + * Returns an object whose properties have the value 'true' + * when they will be absent when used in a 'with' statement. + */ + [Symbol.unscopables](): { + copyWithin: boolean; + entries: boolean; + fill: boolean; + find: boolean; + findIndex: boolean; + keys: boolean; + values: boolean; + }; +} + + +//// [index.js] +class Test extends Array1 { +} +//// [other.js] diff --git a/tests/baselines/reference/indexSignatureInOtherFile.symbols b/tests/baselines/reference/indexSignatureInOtherFile.symbols new file mode 100644 index 00000000000..fdac2f2d68c --- /dev/null +++ b/tests/baselines/reference/indexSignatureInOtherFile.symbols @@ -0,0 +1,87 @@ +=== tests/cases/compiler/index.ts === +class Test extends Array1 { +>Test : Symbol(Test, Decl(index.ts, 0, 0)) +>Array1 : Symbol(Array1, Decl(other.ts, 0, 0), Decl(other.ts, 9, 11), Decl(other.ts, 9, 38), Decl(other.ts, 14, 1)) + + [key: symbol]: string +>key : Symbol(key, Decl(index.ts, 1, 3)) +} + +=== tests/cases/compiler/other.ts === +interface Array1 { +>Array1 : Symbol(Array1, Decl(other.ts, 0, 0), Decl(other.ts, 9, 11), Decl(other.ts, 9, 38), Decl(other.ts, 14, 1)) +>T : Symbol(T, Decl(other.ts, 0, 17), Decl(other.ts, 12, 17), Decl(other.ts, 17, 17)) + + length: number; +>length : Symbol(Array1.length, Decl(other.ts, 0, 21)) + + [n: number]: T; +>n : Symbol(n, Decl(other.ts, 2, 3)) +>T : Symbol(T, Decl(other.ts, 0, 17), Decl(other.ts, 12, 17), Decl(other.ts, 17, 17)) +} + +interface ArrayConstructor1 { +>ArrayConstructor1 : Symbol(ArrayConstructor1, Decl(other.ts, 3, 1)) + + new(arrayLength?: number): Array1; +>arrayLength : Symbol(arrayLength, Decl(other.ts, 6, 6)) +>Array1 : Symbol(Array1, Decl(other.ts, 0, 0), Decl(other.ts, 9, 11), Decl(other.ts, 9, 38), Decl(other.ts, 14, 1)) +} + +declare var Array1: ArrayConstructor1; +>Array1 : Symbol(Array1, Decl(other.ts, 0, 0), Decl(other.ts, 9, 11), Decl(other.ts, 9, 38), Decl(other.ts, 14, 1)) +>ArrayConstructor1 : Symbol(ArrayConstructor1, Decl(other.ts, 3, 1)) + +// iterable.d.ts +interface Array1 { +>Array1 : Symbol(Array1, Decl(other.ts, 0, 0), Decl(other.ts, 9, 11), Decl(other.ts, 9, 38), Decl(other.ts, 14, 1)) +>T : Symbol(T, Decl(other.ts, 0, 17), Decl(other.ts, 12, 17), Decl(other.ts, 17, 17)) + + [Symbol.iterator](): IterableIterator; +>[Symbol.iterator] : Symbol(Array1[Symbol.iterator], Decl(other.ts, 12, 21)) +>Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.es2015.iterable.d.ts, --, --)) +>T : Symbol(T, Decl(other.ts, 0, 17), Decl(other.ts, 12, 17), Decl(other.ts, 17, 17)) +} + +// symbol.wellknown.d.ts +interface Array1 { +>Array1 : Symbol(Array1, Decl(other.ts, 0, 0), Decl(other.ts, 9, 11), Decl(other.ts, 9, 38), Decl(other.ts, 14, 1)) +>T : Symbol(T, Decl(other.ts, 0, 17), Decl(other.ts, 12, 17), Decl(other.ts, 17, 17)) + + /** + * Returns an object whose properties have the value 'true' + * when they will be absent when used in a 'with' statement. + */ + [Symbol.unscopables](): { +>[Symbol.unscopables] : Symbol(Array1[Symbol.unscopables], Decl(other.ts, 17, 21)) +>Symbol.unscopables : Symbol(SymbolConstructor.unscopables, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>unscopables : Symbol(SymbolConstructor.unscopables, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + + copyWithin: boolean; +>copyWithin : Symbol(copyWithin, Decl(other.ts, 22, 27)) + + entries: boolean; +>entries : Symbol(entries, Decl(other.ts, 23, 26)) + + fill: boolean; +>fill : Symbol(fill, Decl(other.ts, 24, 23)) + + find: boolean; +>find : Symbol(find, Decl(other.ts, 25, 20)) + + findIndex: boolean; +>findIndex : Symbol(findIndex, Decl(other.ts, 26, 20)) + + keys: boolean; +>keys : Symbol(keys, Decl(other.ts, 27, 25)) + + values: boolean; +>values : Symbol(values, Decl(other.ts, 28, 20)) + + }; +} + diff --git a/tests/baselines/reference/indexSignatureInOtherFile.types b/tests/baselines/reference/indexSignatureInOtherFile.types new file mode 100644 index 00000000000..0492daf3d80 --- /dev/null +++ b/tests/baselines/reference/indexSignatureInOtherFile.types @@ -0,0 +1,71 @@ +=== tests/cases/compiler/index.ts === +class Test extends Array1 { +>Test : Test +>Array1 : Array1 + + [key: symbol]: string +>key : symbol +} + +=== tests/cases/compiler/other.ts === +interface Array1 { + length: number; +>length : number + + [n: number]: T; +>n : number +} + +interface ArrayConstructor1 { + new(arrayLength?: number): Array1; +>arrayLength : number +} + +declare var Array1: ArrayConstructor1; +>Array1 : ArrayConstructor1 + +// iterable.d.ts +interface Array1 { + [Symbol.iterator](): IterableIterator; +>[Symbol.iterator] : () => IterableIterator +>Symbol.iterator : unique symbol +>Symbol : SymbolConstructor +>iterator : unique symbol +} + +// symbol.wellknown.d.ts +interface Array1 { + /** + * Returns an object whose properties have the value 'true' + * when they will be absent when used in a 'with' statement. + */ + [Symbol.unscopables](): { +>[Symbol.unscopables] : () => { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean;} +>Symbol.unscopables : unique symbol +>Symbol : SymbolConstructor +>unscopables : unique symbol + + copyWithin: boolean; +>copyWithin : boolean + + entries: boolean; +>entries : boolean + + fill: boolean; +>fill : boolean + + find: boolean; +>find : boolean + + findIndex: boolean; +>findIndex : boolean + + keys: boolean; +>keys : boolean + + values: boolean; +>values : boolean + + }; +} + diff --git a/tests/baselines/reference/indexSignatureInOtherFile1.errors.txt b/tests/baselines/reference/indexSignatureInOtherFile1.errors.txt new file mode 100644 index 00000000000..10bf2418bdd --- /dev/null +++ b/tests/baselines/reference/indexSignatureInOtherFile1.errors.txt @@ -0,0 +1,48 @@ +tests/cases/compiler/index.ts(2,3): error TS2411: Property '[Symbol.iterator]' of type '() => IterableIterator' is not assignable to 'symbol' index type 'string'. +tests/cases/compiler/index.ts(2,3): error TS2411: Property '[Symbol.unscopables]' of type '() => { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }' is not assignable to 'symbol' index type 'string'. + + +==== tests/cases/compiler/other.ts (0 errors) ==== + interface Array1 { + length: number; + [n: number]: T; + } + + interface ArrayConstructor1 { + new(arrayLength?: number): Array1; + } + + declare var Array1: ArrayConstructor1; + + // iterable.d.ts + interface Array1 { + [Symbol.iterator](): IterableIterator; + } + + // symbol.wellknown.d.ts + interface Array1 { + /** + * Returns an object whose properties have the value 'true' + * when they will be absent when used in a 'with' statement. + */ + [Symbol.unscopables](): { + copyWithin: boolean; + entries: boolean; + fill: boolean; + find: boolean; + findIndex: boolean; + keys: boolean; + values: boolean; + }; + } + +==== tests/cases/compiler/index.ts (2 errors) ==== + class Test extends Array1 { + [key: symbol]: string + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '[Symbol.iterator]' of type '() => IterableIterator' is not assignable to 'symbol' index type 'string'. +!!! related TS2728 tests/cases/compiler/other.ts:14:3: '[Symbol.iterator]' is declared here. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '[Symbol.unscopables]' of type '() => { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }' is not assignable to 'symbol' index type 'string'. +!!! related TS2728 tests/cases/compiler/other.ts:23:3: '[Symbol.unscopables]' is declared here. + } \ No newline at end of file diff --git a/tests/baselines/reference/indexSignatureInOtherFile1.js b/tests/baselines/reference/indexSignatureInOtherFile1.js new file mode 100644 index 00000000000..e756f9fd8e0 --- /dev/null +++ b/tests/baselines/reference/indexSignatureInOtherFile1.js @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/indexSignatureInOtherFile1.ts] //// + +//// [other.ts] +interface Array1 { + length: number; + [n: number]: T; +} + +interface ArrayConstructor1 { + new(arrayLength?: number): Array1; +} + +declare var Array1: ArrayConstructor1; + +// iterable.d.ts +interface Array1 { + [Symbol.iterator](): IterableIterator; +} + +// symbol.wellknown.d.ts +interface Array1 { + /** + * Returns an object whose properties have the value 'true' + * when they will be absent when used in a 'with' statement. + */ + [Symbol.unscopables](): { + copyWithin: boolean; + entries: boolean; + fill: boolean; + find: boolean; + findIndex: boolean; + keys: boolean; + values: boolean; + }; +} + +//// [index.ts] +class Test extends Array1 { + [key: symbol]: string +} + +//// [other.js] +//// [index.js] +class Test extends Array1 { +} diff --git a/tests/baselines/reference/indexSignatureInOtherFile1.symbols b/tests/baselines/reference/indexSignatureInOtherFile1.symbols new file mode 100644 index 00000000000..5eb78c14226 --- /dev/null +++ b/tests/baselines/reference/indexSignatureInOtherFile1.symbols @@ -0,0 +1,86 @@ +=== tests/cases/compiler/other.ts === +interface Array1 { +>Array1 : Symbol(Array1, Decl(other.ts, 0, 0), Decl(other.ts, 9, 11), Decl(other.ts, 9, 38), Decl(other.ts, 14, 1)) +>T : Symbol(T, Decl(other.ts, 0, 17), Decl(other.ts, 12, 17), Decl(other.ts, 17, 17)) + + length: number; +>length : Symbol(Array1.length, Decl(other.ts, 0, 21)) + + [n: number]: T; +>n : Symbol(n, Decl(other.ts, 2, 3)) +>T : Symbol(T, Decl(other.ts, 0, 17), Decl(other.ts, 12, 17), Decl(other.ts, 17, 17)) +} + +interface ArrayConstructor1 { +>ArrayConstructor1 : Symbol(ArrayConstructor1, Decl(other.ts, 3, 1)) + + new(arrayLength?: number): Array1; +>arrayLength : Symbol(arrayLength, Decl(other.ts, 6, 6)) +>Array1 : Symbol(Array1, Decl(other.ts, 0, 0), Decl(other.ts, 9, 11), Decl(other.ts, 9, 38), Decl(other.ts, 14, 1)) +} + +declare var Array1: ArrayConstructor1; +>Array1 : Symbol(Array1, Decl(other.ts, 0, 0), Decl(other.ts, 9, 11), Decl(other.ts, 9, 38), Decl(other.ts, 14, 1)) +>ArrayConstructor1 : Symbol(ArrayConstructor1, Decl(other.ts, 3, 1)) + +// iterable.d.ts +interface Array1 { +>Array1 : Symbol(Array1, Decl(other.ts, 0, 0), Decl(other.ts, 9, 11), Decl(other.ts, 9, 38), Decl(other.ts, 14, 1)) +>T : Symbol(T, Decl(other.ts, 0, 17), Decl(other.ts, 12, 17), Decl(other.ts, 17, 17)) + + [Symbol.iterator](): IterableIterator; +>[Symbol.iterator] : Symbol(Array1[Symbol.iterator], Decl(other.ts, 12, 21)) +>Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.es2015.iterable.d.ts, --, --)) +>T : Symbol(T, Decl(other.ts, 0, 17), Decl(other.ts, 12, 17), Decl(other.ts, 17, 17)) +} + +// symbol.wellknown.d.ts +interface Array1 { +>Array1 : Symbol(Array1, Decl(other.ts, 0, 0), Decl(other.ts, 9, 11), Decl(other.ts, 9, 38), Decl(other.ts, 14, 1)) +>T : Symbol(T, Decl(other.ts, 0, 17), Decl(other.ts, 12, 17), Decl(other.ts, 17, 17)) + + /** + * Returns an object whose properties have the value 'true' + * when they will be absent when used in a 'with' statement. + */ + [Symbol.unscopables](): { +>[Symbol.unscopables] : Symbol(Array1[Symbol.unscopables], Decl(other.ts, 17, 21)) +>Symbol.unscopables : Symbol(SymbolConstructor.unscopables, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>unscopables : Symbol(SymbolConstructor.unscopables, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + + copyWithin: boolean; +>copyWithin : Symbol(copyWithin, Decl(other.ts, 22, 27)) + + entries: boolean; +>entries : Symbol(entries, Decl(other.ts, 23, 26)) + + fill: boolean; +>fill : Symbol(fill, Decl(other.ts, 24, 23)) + + find: boolean; +>find : Symbol(find, Decl(other.ts, 25, 20)) + + findIndex: boolean; +>findIndex : Symbol(findIndex, Decl(other.ts, 26, 20)) + + keys: boolean; +>keys : Symbol(keys, Decl(other.ts, 27, 25)) + + values: boolean; +>values : Symbol(values, Decl(other.ts, 28, 20)) + + }; +} + +=== tests/cases/compiler/index.ts === +class Test extends Array1 { +>Test : Symbol(Test, Decl(index.ts, 0, 0)) +>Array1 : Symbol(Array1, Decl(other.ts, 0, 0), Decl(other.ts, 9, 11), Decl(other.ts, 9, 38), Decl(other.ts, 14, 1)) + + [key: symbol]: string +>key : Symbol(key, Decl(index.ts, 1, 3)) +} diff --git a/tests/baselines/reference/indexSignatureInOtherFile1.types b/tests/baselines/reference/indexSignatureInOtherFile1.types new file mode 100644 index 00000000000..07eac7a919c --- /dev/null +++ b/tests/baselines/reference/indexSignatureInOtherFile1.types @@ -0,0 +1,70 @@ +=== tests/cases/compiler/other.ts === +interface Array1 { + length: number; +>length : number + + [n: number]: T; +>n : number +} + +interface ArrayConstructor1 { + new(arrayLength?: number): Array1; +>arrayLength : number +} + +declare var Array1: ArrayConstructor1; +>Array1 : ArrayConstructor1 + +// iterable.d.ts +interface Array1 { + [Symbol.iterator](): IterableIterator; +>[Symbol.iterator] : () => IterableIterator +>Symbol.iterator : unique symbol +>Symbol : SymbolConstructor +>iterator : unique symbol +} + +// symbol.wellknown.d.ts +interface Array1 { + /** + * Returns an object whose properties have the value 'true' + * when they will be absent when used in a 'with' statement. + */ + [Symbol.unscopables](): { +>[Symbol.unscopables] : () => { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean;} +>Symbol.unscopables : unique symbol +>Symbol : SymbolConstructor +>unscopables : unique symbol + + copyWithin: boolean; +>copyWithin : boolean + + entries: boolean; +>entries : boolean + + fill: boolean; +>fill : boolean + + find: boolean; +>find : boolean + + findIndex: boolean; +>findIndex : boolean + + keys: boolean; +>keys : boolean + + values: boolean; +>values : boolean + + }; +} + +=== tests/cases/compiler/index.ts === +class Test extends Array1 { +>Test : Test +>Array1 : Array1 + + [key: symbol]: string +>key : symbol +} diff --git a/tests/baselines/reference/symbolProperty32.errors.txt b/tests/baselines/reference/symbolProperty32.errors.txt index 9bacef82a7c..18ffae948f9 100644 --- a/tests/baselines/reference/symbolProperty32.errors.txt +++ b/tests/baselines/reference/symbolProperty32.errors.txt @@ -1,14 +1,15 @@ -tests/cases/conformance/es6/Symbols/symbolProperty32.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/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]() { - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'. 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; }'. +!!! related TS2728 tests/cases/conformance/es6/Symbols/symbolProperty32.ts:2:5: '[Symbol.toStringTag]' is declared here. } \ No newline at end of file diff --git a/tests/cases/compiler/indexSignatureInOtherFile.ts b/tests/cases/compiler/indexSignatureInOtherFile.ts new file mode 100644 index 00000000000..a5b28bfc67b --- /dev/null +++ b/tests/cases/compiler/indexSignatureInOtherFile.ts @@ -0,0 +1,39 @@ +// @target: es2015 +// @Filename: index.ts +class Test extends Array1 { + [key: symbol]: string +} + +// @Filename: other.ts +interface Array1 { + length: number; + [n: number]: T; +} + +interface ArrayConstructor1 { + new(arrayLength?: number): Array1; +} + +declare var Array1: ArrayConstructor1; + +// iterable.d.ts +interface Array1 { + [Symbol.iterator](): IterableIterator; +} + +// symbol.wellknown.d.ts +interface Array1 { + /** + * Returns an object whose properties have the value 'true' + * when they will be absent when used in a 'with' statement. + */ + [Symbol.unscopables](): { + copyWithin: boolean; + entries: boolean; + fill: boolean; + find: boolean; + findIndex: boolean; + keys: boolean; + values: boolean; + }; +} diff --git a/tests/cases/compiler/indexSignatureInOtherFile1.ts b/tests/cases/compiler/indexSignatureInOtherFile1.ts new file mode 100644 index 00000000000..0edd8b1c457 --- /dev/null +++ b/tests/cases/compiler/indexSignatureInOtherFile1.ts @@ -0,0 +1,39 @@ +// @target: es2015 +// @Filename: other.ts +interface Array1 { + length: number; + [n: number]: T; +} + +interface ArrayConstructor1 { + new(arrayLength?: number): Array1; +} + +declare var Array1: ArrayConstructor1; + +// iterable.d.ts +interface Array1 { + [Symbol.iterator](): IterableIterator; +} + +// symbol.wellknown.d.ts +interface Array1 { + /** + * Returns an object whose properties have the value 'true' + * when they will be absent when used in a 'with' statement. + */ + [Symbol.unscopables](): { + copyWithin: boolean; + entries: boolean; + fill: boolean; + find: boolean; + findIndex: boolean; + keys: boolean; + values: boolean; + }; +} + +// @Filename: index.ts +class Test extends Array1 { + [key: symbol]: string +} \ No newline at end of file