-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support interpreting non-literal computed properties in classes as im…
…plicit index signatures (#59860)
- Loading branch information
Showing
34 changed files
with
400 additions
and
81 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
ES5SymbolProperty5.ts(7,26): error TS2554: Expected 0 arguments, but got 1. | ||
|
||
|
||
==== ES5SymbolProperty5.ts (1 errors) ==== | ||
var Symbol: { iterator: symbol }; | ||
|
||
class C { | ||
[Symbol.iterator]() { } | ||
} | ||
|
||
(new C)[Symbol.iterator](0) // Should error | ||
~ | ||
!!! error TS2554: Expected 0 arguments, but got 1. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/baselines/reference/classNonUniqueSymbolMethodHasSymbolIndexer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//// [tests/cases/compiler/classNonUniqueSymbolMethodHasSymbolIndexer.ts] //// | ||
|
||
//// [classNonUniqueSymbolMethodHasSymbolIndexer.ts] | ||
declare const a: symbol; | ||
export class A { | ||
[a]() { return 1 }; | ||
} | ||
declare const e1: A[typeof a]; // no error, `A` has `symbol` index | ||
|
||
type Constructor = new (...args: any[]) => {}; | ||
declare function Mix<T extends Constructor>(classish: T): T & (new (...args: any[]) => {mixed: true}); | ||
|
||
export const Mixer = Mix(class { | ||
[a]() { return 1 }; | ||
}); | ||
|
||
|
||
//// [classNonUniqueSymbolMethodHasSymbolIndexer.js] | ||
export class A { | ||
[a]() { return 1; } | ||
; | ||
} | ||
export const Mixer = Mix(class { | ||
[a]() { return 1; } | ||
; | ||
}); | ||
|
||
|
||
//// [classNonUniqueSymbolMethodHasSymbolIndexer.d.ts] | ||
export declare class A { | ||
[x: symbol]: () => number; | ||
} | ||
export declare const Mixer: { | ||
new (): { | ||
[x: symbol]: () => number; | ||
}; | ||
} & (new (...args: any[]) => { | ||
mixed: true; | ||
}); |
42 changes: 42 additions & 0 deletions
42
tests/baselines/reference/classNonUniqueSymbolMethodHasSymbolIndexer.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//// [tests/cases/compiler/classNonUniqueSymbolMethodHasSymbolIndexer.ts] //// | ||
|
||
=== classNonUniqueSymbolMethodHasSymbolIndexer.ts === | ||
declare const a: symbol; | ||
>a : Symbol(a, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 0, 13)) | ||
|
||
export class A { | ||
>A : Symbol(A, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 0, 24)) | ||
|
||
[a]() { return 1 }; | ||
>[a] : Symbol(A[a], Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 1, 16)) | ||
>a : Symbol(a, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 0, 13)) | ||
} | ||
declare const e1: A[typeof a]; // no error, `A` has `symbol` index | ||
>e1 : Symbol(e1, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 4, 13)) | ||
>A : Symbol(A, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 0, 24)) | ||
>a : Symbol(a, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 0, 13)) | ||
|
||
type Constructor = new (...args: any[]) => {}; | ||
>Constructor : Symbol(Constructor, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 4, 30)) | ||
>args : Symbol(args, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 6, 24)) | ||
|
||
declare function Mix<T extends Constructor>(classish: T): T & (new (...args: any[]) => {mixed: true}); | ||
>Mix : Symbol(Mix, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 6, 46)) | ||
>T : Symbol(T, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 7, 21)) | ||
>Constructor : Symbol(Constructor, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 4, 30)) | ||
>classish : Symbol(classish, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 7, 44)) | ||
>T : Symbol(T, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 7, 21)) | ||
>T : Symbol(T, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 7, 21)) | ||
>args : Symbol(args, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 7, 68)) | ||
>mixed : Symbol(mixed, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 7, 88)) | ||
|
||
export const Mixer = Mix(class { | ||
>Mixer : Symbol(Mixer, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 9, 12)) | ||
>Mix : Symbol(Mix, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 6, 46)) | ||
|
||
[a]() { return 1 }; | ||
>[a] : Symbol((Anonymous class)[a], Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 9, 32)) | ||
>a : Symbol(a, Decl(classNonUniqueSymbolMethodHasSymbolIndexer.ts, 0, 13)) | ||
|
||
}); | ||
|
63 changes: 63 additions & 0 deletions
63
tests/baselines/reference/classNonUniqueSymbolMethodHasSymbolIndexer.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//// [tests/cases/compiler/classNonUniqueSymbolMethodHasSymbolIndexer.ts] //// | ||
|
||
=== classNonUniqueSymbolMethodHasSymbolIndexer.ts === | ||
declare const a: symbol; | ||
>a : symbol | ||
> : ^^^^^^ | ||
|
||
export class A { | ||
>A : A | ||
> : ^ | ||
|
||
[a]() { return 1 }; | ||
>[a] : () => number | ||
> : ^^^^^^^^^^^^ | ||
>a : symbol | ||
> : ^^^^^^ | ||
>1 : 1 | ||
> : ^ | ||
} | ||
declare const e1: A[typeof a]; // no error, `A` has `symbol` index | ||
>e1 : () => number | ||
> : ^^^^^^^^^^^^ | ||
>a : symbol | ||
> : ^^^^^^ | ||
|
||
type Constructor = new (...args: any[]) => {}; | ||
>Constructor : Constructor | ||
> : ^^^^^^^^^^^ | ||
>args : any[] | ||
> : ^^^^^ | ||
|
||
declare function Mix<T extends Constructor>(classish: T): T & (new (...args: any[]) => {mixed: true}); | ||
>Mix : <T extends Constructor>(classish: T) => T & (new (...args: any[]) => { mixed: true; }) | ||
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ | ||
>classish : T | ||
> : ^ | ||
>args : any[] | ||
> : ^^^^^ | ||
>mixed : true | ||
> : ^^^^ | ||
>true : true | ||
> : ^^^^ | ||
|
||
export const Mixer = Mix(class { | ||
>Mixer : typeof (Anonymous class) & (new (...args: any[]) => { mixed: true; }) | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^ | ||
>Mix(class { [a]() { return 1 };}) : typeof (Anonymous class) & (new (...args: any[]) => { mixed: true; }) | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ ^ | ||
>Mix : <T extends Constructor>(classish: T) => T & (new (...args: any[]) => { mixed: true; }) | ||
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ | ||
>class { [a]() { return 1 };} : typeof (Anonymous class) | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
[a]() { return 1 }; | ||
>[a] : () => number | ||
> : ^^^^^^^^^^^^ | ||
>a : symbol | ||
> : ^^^^^^ | ||
>1 : 1 | ||
> : ^ | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,5 @@ exports.C = C; | |
|
||
//// [main.d.ts] | ||
export declare class C { | ||
[x: number]: () => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.