From 2d61217b8d7c46a5c3c89497eaa9b4d07e7b8bb1 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 20 May 2020 20:34:12 +0800 Subject: [PATCH] add more cases --- src/harness/vfsUtil.ts | 2 +- .../staticIndexSignature1.errors.txt | 4 +- .../reference/staticIndexSignature1.symbols | 2 +- .../reference/staticIndexSignature1.types | 2 +- .../staticIndexSignature2.errors.txt | 12 +- .../reference/staticIndexSignature2.symbols | 2 +- .../reference/staticIndexSignature2.types | 2 +- .../staticIndexSignature3.errors.txt | 60 +++++++ .../reference/staticIndexSignature3.js | 78 ++++++++ .../reference/staticIndexSignature3.symbols | 70 ++++++++ .../reference/staticIndexSignature3.types | 86 +++++++++ .../staticIndexSignature4.errors.txt | 51 ++++++ .../reference/staticIndexSignature4.js | 72 ++++++++ .../reference/staticIndexSignature4.symbols | 102 +++++++++++ .../reference/staticIndexSignature4.types | 169 ++++++++++++++++++ .../reference/staticIndexSignature5.js | 32 ++++ .../reference/staticIndexSignature5.symbols | 61 +++++++ .../reference/staticIndexSignature5.types | 53 ++++++ .../staticIndexSignature1.ts | 1 - .../staticIndexSignature2.ts | 1 - .../staticIndexSignature3.ts | 28 +++ .../staticIndexSignature4.ts | 37 ++++ .../staticIndexSignature5.ts | 24 +++ 23 files changed, 936 insertions(+), 15 deletions(-) create mode 100644 tests/baselines/reference/staticIndexSignature3.errors.txt create mode 100644 tests/baselines/reference/staticIndexSignature3.js create mode 100644 tests/baselines/reference/staticIndexSignature3.symbols create mode 100644 tests/baselines/reference/staticIndexSignature3.types create mode 100644 tests/baselines/reference/staticIndexSignature4.errors.txt create mode 100644 tests/baselines/reference/staticIndexSignature4.js create mode 100644 tests/baselines/reference/staticIndexSignature4.symbols create mode 100644 tests/baselines/reference/staticIndexSignature4.types create mode 100644 tests/baselines/reference/staticIndexSignature5.js create mode 100644 tests/baselines/reference/staticIndexSignature5.symbols create mode 100644 tests/baselines/reference/staticIndexSignature5.types rename tests/cases/{compiler => conformance/classes/staticIndexSignature}/staticIndexSignature1.ts (87%) rename tests/cases/{compiler => conformance/classes/staticIndexSignature}/staticIndexSignature2.ts (88%) create mode 100644 tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts create mode 100644 tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature4.ts create mode 100644 tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature5.ts diff --git a/src/harness/vfsUtil.ts b/src/harness/vfsUtil.ts index 76475b00360b2..dab81fc3404ff 100644 --- a/src/harness/vfsUtil.ts +++ b/src/harness/vfsUtil.ts @@ -663,7 +663,7 @@ namespace vfs { if (!isFile(node)) throw createIOError("EBADF"); const buffer = this._getBuffer(node).slice(); - return encoding ? buffer.toString(encoding) : buffer; + return encoding ? buffer.toString(encoding as any) : buffer; } /** diff --git a/tests/baselines/reference/staticIndexSignature1.errors.txt b/tests/baselines/reference/staticIndexSignature1.errors.txt index ffc3f9acffb73..b6bb9cf2e1c3c 100644 --- a/tests/baselines/reference/staticIndexSignature1.errors.txt +++ b/tests/baselines/reference/staticIndexSignature1.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/staticIndexSignature1.ts(10,1): error TS2322: Type '2' is not assignable to type '42'. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature1.ts(10,1): error TS2322: Type '2' is not assignable to type '42'. -==== tests/cases/compiler/staticIndexSignature1.ts (1 errors) ==== +==== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature1.ts (1 errors) ==== class C { static [s: string]: number; static [s: number]: 42 diff --git a/tests/baselines/reference/staticIndexSignature1.symbols b/tests/baselines/reference/staticIndexSignature1.symbols index 5868eb4fdc0f3..b672f4e22a7e2 100644 --- a/tests/baselines/reference/staticIndexSignature1.symbols +++ b/tests/baselines/reference/staticIndexSignature1.symbols @@ -1,4 +1,4 @@ -=== tests/cases/compiler/staticIndexSignature1.ts === +=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature1.ts === class C { >C : Symbol(C, Decl(staticIndexSignature1.ts, 0, 0)) diff --git a/tests/baselines/reference/staticIndexSignature1.types b/tests/baselines/reference/staticIndexSignature1.types index e97b393bc7b9e..6a4de3da49568 100644 --- a/tests/baselines/reference/staticIndexSignature1.types +++ b/tests/baselines/reference/staticIndexSignature1.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/staticIndexSignature1.ts === +=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature1.ts === class C { >C : C diff --git a/tests/baselines/reference/staticIndexSignature2.errors.txt b/tests/baselines/reference/staticIndexSignature2.errors.txt index dab2c24944979..8bdee878f7654 100644 --- a/tests/baselines/reference/staticIndexSignature2.errors.txt +++ b/tests/baselines/reference/staticIndexSignature2.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/staticIndexSignature2.ts(6,1): error TS2542: Index signature in type 'typeof C' only permits reading. -tests/cases/compiler/staticIndexSignature2.ts(7,1): error TS2542: Index signature in type 'typeof C' only permits reading. -tests/cases/compiler/staticIndexSignature2.ts(9,1): error TS2542: Index signature in type 'typeof C' only permits reading. -tests/cases/compiler/staticIndexSignature2.ts(10,1): error TS2322: Type '2' is not assignable to type '42'. -tests/cases/compiler/staticIndexSignature2.ts(10,1): error TS2542: Index signature in type 'typeof C' only permits reading. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts(6,1): error TS2542: Index signature in type 'typeof C' only permits reading. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts(7,1): error TS2542: Index signature in type 'typeof C' only permits reading. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts(9,1): error TS2542: Index signature in type 'typeof C' only permits reading. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts(10,1): error TS2322: Type '2' is not assignable to type '42'. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts(10,1): error TS2542: Index signature in type 'typeof C' only permits reading. -==== tests/cases/compiler/staticIndexSignature2.ts (5 errors) ==== +==== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts (5 errors) ==== class C { static readonly [s: string]: number; static readonly [s: number]: 42 diff --git a/tests/baselines/reference/staticIndexSignature2.symbols b/tests/baselines/reference/staticIndexSignature2.symbols index eb6331b30f6b2..abbf36f9733b4 100644 --- a/tests/baselines/reference/staticIndexSignature2.symbols +++ b/tests/baselines/reference/staticIndexSignature2.symbols @@ -1,4 +1,4 @@ -=== tests/cases/compiler/staticIndexSignature2.ts === +=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts === class C { >C : Symbol(C, Decl(staticIndexSignature2.ts, 0, 0)) diff --git a/tests/baselines/reference/staticIndexSignature2.types b/tests/baselines/reference/staticIndexSignature2.types index 5121786907a98..dfe75d2660096 100644 --- a/tests/baselines/reference/staticIndexSignature2.types +++ b/tests/baselines/reference/staticIndexSignature2.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/staticIndexSignature2.ts === +=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts === class C { >C : C diff --git a/tests/baselines/reference/staticIndexSignature3.errors.txt b/tests/baselines/reference/staticIndexSignature3.errors.txt new file mode 100644 index 0000000000000..b6fa831450b62 --- /dev/null +++ b/tests/baselines/reference/staticIndexSignature3.errors.txt @@ -0,0 +1,60 @@ +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts(21,11): error TS7053: Element implicitly has an 'any' type because expression of type '"f"' can't be used to index type 'typeof D'. + Property 'f' does not exist on type 'typeof D'. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts(22,11): error TS7053: Element implicitly has an 'any' type because expression of type '42' can't be used to index type 'typeof D'. + Property '42' does not exist on type 'typeof D'. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts(23,11): error TS7053: Element implicitly has an 'any' type because expression of type '"f"' can't be used to index type 'typeof ED'. + Property 'f' does not exist on type 'typeof ED'. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts(24,11): error TS7053: Element implicitly has an 'any' type because expression of type '42' can't be used to index type 'typeof ED'. + Property '42' does not exist on type 'typeof ED'. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts(25,11): error TS7053: Element implicitly has an 'any' type because expression of type '"f"' can't be used to index type 'typeof DD'. + Property 'f' does not exist on type 'typeof DD'. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts(26,11): error TS7053: Element implicitly has an 'any' type because expression of type '42' can't be used to index type 'typeof DD'. + Property '42' does not exist on type 'typeof DD'. + + +==== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts (6 errors) ==== + class B { + static readonly [s: string]: number; + static readonly [s: number]: 42 | 233 + } + + class D extends B { + static readonly [s: string]: number + } + + class ED extends D { + static readonly [s: string]: boolean + static readonly [s: number]: 1 + } + + class DD extends D { + static readonly [s: string]: 421 + } + + const a = B["f"]; + const b = B[42]; + const c = D["f"] + ~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"f"' can't be used to index type 'typeof D'. +!!! error TS7053: Property 'f' does not exist on type 'typeof D'. + const d = D[42] + ~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '42' can't be used to index type 'typeof D'. +!!! error TS7053: Property '42' does not exist on type 'typeof D'. + const e = ED["f"] + ~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"f"' can't be used to index type 'typeof ED'. +!!! error TS7053: Property 'f' does not exist on type 'typeof ED'. + const f = ED[42] + ~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '42' can't be used to index type 'typeof ED'. +!!! error TS7053: Property '42' does not exist on type 'typeof ED'. + const g = DD["f"] + ~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"f"' can't be used to index type 'typeof DD'. +!!! error TS7053: Property 'f' does not exist on type 'typeof DD'. + const h = DD[42] + ~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '42' can't be used to index type 'typeof DD'. +!!! error TS7053: Property '42' does not exist on type 'typeof DD'. + \ No newline at end of file diff --git a/tests/baselines/reference/staticIndexSignature3.js b/tests/baselines/reference/staticIndexSignature3.js new file mode 100644 index 0000000000000..b146906a8ff3b --- /dev/null +++ b/tests/baselines/reference/staticIndexSignature3.js @@ -0,0 +1,78 @@ +//// [staticIndexSignature3.ts] +class B { + static readonly [s: string]: number; + static readonly [s: number]: 42 | 233 +} + +class D extends B { + static readonly [s: string]: number +} + +class ED extends D { + static readonly [s: string]: boolean + static readonly [s: number]: 1 +} + +class DD extends D { + static readonly [s: string]: 421 +} + +const a = B["f"]; +const b = B[42]; +const c = D["f"] +const d = D[42] +const e = ED["f"] +const f = ED[42] +const g = DD["f"] +const h = DD[42] + + +//// [staticIndexSignature3.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var B = /** @class */ (function () { + function B() { + } + return B; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + return _super !== null && _super.apply(this, arguments) || this; + } + return D; +}(B)); +var ED = /** @class */ (function (_super) { + __extends(ED, _super); + function ED() { + return _super !== null && _super.apply(this, arguments) || this; + } + return ED; +}(D)); +var DD = /** @class */ (function (_super) { + __extends(DD, _super); + function DD() { + return _super !== null && _super.apply(this, arguments) || this; + } + return DD; +}(D)); +var a = B["f"]; +var b = B[42]; +var c = D["f"]; +var d = D[42]; +var e = ED["f"]; +var f = ED[42]; +var g = DD["f"]; +var h = DD[42]; diff --git a/tests/baselines/reference/staticIndexSignature3.symbols b/tests/baselines/reference/staticIndexSignature3.symbols new file mode 100644 index 0000000000000..51a9954bf5e8f --- /dev/null +++ b/tests/baselines/reference/staticIndexSignature3.symbols @@ -0,0 +1,70 @@ +=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts === +class B { +>B : Symbol(B, Decl(staticIndexSignature3.ts, 0, 0)) + + static readonly [s: string]: number; +>s : Symbol(s, Decl(staticIndexSignature3.ts, 1, 21)) + + static readonly [s: number]: 42 | 233 +>s : Symbol(s, Decl(staticIndexSignature3.ts, 2, 21)) +} + +class D extends B { +>D : Symbol(D, Decl(staticIndexSignature3.ts, 3, 1)) +>B : Symbol(B, Decl(staticIndexSignature3.ts, 0, 0)) + + static readonly [s: string]: number +>s : Symbol(s, Decl(staticIndexSignature3.ts, 6, 21)) +} + +class ED extends D { +>ED : Symbol(ED, Decl(staticIndexSignature3.ts, 7, 1)) +>D : Symbol(D, Decl(staticIndexSignature3.ts, 3, 1)) + + static readonly [s: string]: boolean +>s : Symbol(s, Decl(staticIndexSignature3.ts, 10, 21)) + + static readonly [s: number]: 1 +>s : Symbol(s, Decl(staticIndexSignature3.ts, 11, 21)) +} + +class DD extends D { +>DD : Symbol(DD, Decl(staticIndexSignature3.ts, 12, 1)) +>D : Symbol(D, Decl(staticIndexSignature3.ts, 3, 1)) + + static readonly [s: string]: 421 +>s : Symbol(s, Decl(staticIndexSignature3.ts, 15, 21)) +} + +const a = B["f"]; +>a : Symbol(a, Decl(staticIndexSignature3.ts, 18, 5)) +>B : Symbol(B, Decl(staticIndexSignature3.ts, 0, 0)) + +const b = B[42]; +>b : Symbol(b, Decl(staticIndexSignature3.ts, 19, 5)) +>B : Symbol(B, Decl(staticIndexSignature3.ts, 0, 0)) + +const c = D["f"] +>c : Symbol(c, Decl(staticIndexSignature3.ts, 20, 5)) +>D : Symbol(D, Decl(staticIndexSignature3.ts, 3, 1)) + +const d = D[42] +>d : Symbol(d, Decl(staticIndexSignature3.ts, 21, 5)) +>D : Symbol(D, Decl(staticIndexSignature3.ts, 3, 1)) + +const e = ED["f"] +>e : Symbol(e, Decl(staticIndexSignature3.ts, 22, 5)) +>ED : Symbol(ED, Decl(staticIndexSignature3.ts, 7, 1)) + +const f = ED[42] +>f : Symbol(f, Decl(staticIndexSignature3.ts, 23, 5)) +>ED : Symbol(ED, Decl(staticIndexSignature3.ts, 7, 1)) + +const g = DD["f"] +>g : Symbol(g, Decl(staticIndexSignature3.ts, 24, 5)) +>DD : Symbol(DD, Decl(staticIndexSignature3.ts, 12, 1)) + +const h = DD[42] +>h : Symbol(h, Decl(staticIndexSignature3.ts, 25, 5)) +>DD : Symbol(DD, Decl(staticIndexSignature3.ts, 12, 1)) + diff --git a/tests/baselines/reference/staticIndexSignature3.types b/tests/baselines/reference/staticIndexSignature3.types new file mode 100644 index 0000000000000..b2f03588e4e4a --- /dev/null +++ b/tests/baselines/reference/staticIndexSignature3.types @@ -0,0 +1,86 @@ +=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts === +class B { +>B : B + + static readonly [s: string]: number; +>s : string + + static readonly [s: number]: 42 | 233 +>s : number +} + +class D extends B { +>D : D +>B : B + + static readonly [s: string]: number +>s : string +} + +class ED extends D { +>ED : ED +>D : D + + static readonly [s: string]: boolean +>s : string + + static readonly [s: number]: 1 +>s : number +} + +class DD extends D { +>DD : DD +>D : D + + static readonly [s: string]: 421 +>s : string +} + +const a = B["f"]; +>a : number +>B["f"] : number +>B : typeof B +>"f" : "f" + +const b = B[42]; +>b : 42 | 233 +>B[42] : 42 | 233 +>B : typeof B +>42 : 42 + +const c = D["f"] +>c : any +>D["f"] : any +>D : typeof D +>"f" : "f" + +const d = D[42] +>d : any +>D[42] : any +>D : typeof D +>42 : 42 + +const e = ED["f"] +>e : any +>ED["f"] : any +>ED : typeof ED +>"f" : "f" + +const f = ED[42] +>f : any +>ED[42] : any +>ED : typeof ED +>42 : 42 + +const g = DD["f"] +>g : any +>DD["f"] : any +>DD : typeof DD +>"f" : "f" + +const h = DD[42] +>h : any +>DD[42] : any +>DD : typeof DD +>42 : 42 + diff --git a/tests/baselines/reference/staticIndexSignature4.errors.txt b/tests/baselines/reference/staticIndexSignature4.errors.txt new file mode 100644 index 0000000000000..9e6e88cfb20a9 --- /dev/null +++ b/tests/baselines/reference/staticIndexSignature4.errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature4.ts(19,5): error TS2542: Index signature in type 'typeof B' only permits reading. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature4.ts(20,5): error TS2542: Index signature in type 'typeof B' only permits reading. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature4.ts(25,5): error TS2542: Index signature in type 'typeof B' only permits reading. +tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature4.ts(26,5): error TS2542: Index signature in type 'typeof B' only permits reading. + + +==== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature4.ts (4 errors) ==== + class B { + static readonly [s: string]: number; + static readonly [s: number]: 42 | 233 + } + + class D { + static [s: string]: number; + static [s: number]: 42 | 233 + } + + interface IB { + static [s: string]: number; + static [s: number]: 42 | 233; + } + + declare const v: number + declare const i: IB + if (v === 0) { + B.a = D.a + ~~~ +!!! error TS2542: Index signature in type 'typeof B' only permits reading. + B[2] = D[2] + ~~~~ +!!! error TS2542: Index signature in type 'typeof B' only permits reading. + } else if (v === 1) { + D.a = B.a + D[2] = B[2] + } else if (v === 2) { + B.a = i.a + ~~~ +!!! error TS2542: Index signature in type 'typeof B' only permits reading. + B[2] = i[2] + ~~~~ +!!! error TS2542: Index signature in type 'typeof B' only permits reading. + D.a = i.a + D[2] = i [2] + } else if (v === 3) { + i.a = B.a + i[2] = B[2] + } else if (v === 4) { + i.a = D.a + i[2] = B[2] + } + \ No newline at end of file diff --git a/tests/baselines/reference/staticIndexSignature4.js b/tests/baselines/reference/staticIndexSignature4.js new file mode 100644 index 0000000000000..4ad5b347ae85b --- /dev/null +++ b/tests/baselines/reference/staticIndexSignature4.js @@ -0,0 +1,72 @@ +//// [staticIndexSignature4.ts] +class B { + static readonly [s: string]: number; + static readonly [s: number]: 42 | 233 +} + +class D { + static [s: string]: number; + static [s: number]: 42 | 233 +} + +interface IB { + static [s: string]: number; + static [s: number]: 42 | 233; +} + +declare const v: number +declare const i: IB +if (v === 0) { + B.a = D.a + B[2] = D[2] +} else if (v === 1) { + D.a = B.a + D[2] = B[2] +} else if (v === 2) { + B.a = i.a + B[2] = i[2] + D.a = i.a + D[2] = i [2] +} else if (v === 3) { + i.a = B.a + i[2] = B[2] +} else if (v === 4) { + i.a = D.a + i[2] = B[2] +} + + +//// [staticIndexSignature4.js] +"use strict"; +var B = /** @class */ (function () { + function B() { + } + return B; +}()); +var D = /** @class */ (function () { + function D() { + } + return D; +}()); +if (v === 0) { + B.a = D.a; + B[2] = D[2]; +} +else if (v === 1) { + D.a = B.a; + D[2] = B[2]; +} +else if (v === 2) { + B.a = i.a; + B[2] = i[2]; + D.a = i.a; + D[2] = i[2]; +} +else if (v === 3) { + i.a = B.a; + i[2] = B[2]; +} +else if (v === 4) { + i.a = D.a; + i[2] = B[2]; +} diff --git a/tests/baselines/reference/staticIndexSignature4.symbols b/tests/baselines/reference/staticIndexSignature4.symbols new file mode 100644 index 0000000000000..198b01bc80288 --- /dev/null +++ b/tests/baselines/reference/staticIndexSignature4.symbols @@ -0,0 +1,102 @@ +=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature4.ts === +class B { +>B : Symbol(B, Decl(staticIndexSignature4.ts, 0, 0)) + + static readonly [s: string]: number; +>s : Symbol(s, Decl(staticIndexSignature4.ts, 1, 21)) + + static readonly [s: number]: 42 | 233 +>s : Symbol(s, Decl(staticIndexSignature4.ts, 2, 21)) +} + +class D { +>D : Symbol(D, Decl(staticIndexSignature4.ts, 3, 1)) + + static [s: string]: number; +>s : Symbol(s, Decl(staticIndexSignature4.ts, 6, 12)) + + static [s: number]: 42 | 233 +>s : Symbol(s, Decl(staticIndexSignature4.ts, 7, 12)) +} + +interface IB { +>IB : Symbol(IB, Decl(staticIndexSignature4.ts, 8, 1)) + + static [s: string]: number; +>s : Symbol(s, Decl(staticIndexSignature4.ts, 11, 12)) + + static [s: number]: 42 | 233; +>s : Symbol(s, Decl(staticIndexSignature4.ts, 12, 12)) +} + +declare const v: number +>v : Symbol(v, Decl(staticIndexSignature4.ts, 15, 13)) + +declare const i: IB +>i : Symbol(i, Decl(staticIndexSignature4.ts, 16, 13)) +>IB : Symbol(IB, Decl(staticIndexSignature4.ts, 8, 1)) + +if (v === 0) { +>v : Symbol(v, Decl(staticIndexSignature4.ts, 15, 13)) + + B.a = D.a +>B : Symbol(B, Decl(staticIndexSignature4.ts, 0, 0)) +>D : Symbol(D, Decl(staticIndexSignature4.ts, 3, 1)) + + B[2] = D[2] +>B : Symbol(B, Decl(staticIndexSignature4.ts, 0, 0)) +>D : Symbol(D, Decl(staticIndexSignature4.ts, 3, 1)) + +} else if (v === 1) { +>v : Symbol(v, Decl(staticIndexSignature4.ts, 15, 13)) + + D.a = B.a +>D : Symbol(D, Decl(staticIndexSignature4.ts, 3, 1)) +>B : Symbol(B, Decl(staticIndexSignature4.ts, 0, 0)) + + D[2] = B[2] +>D : Symbol(D, Decl(staticIndexSignature4.ts, 3, 1)) +>B : Symbol(B, Decl(staticIndexSignature4.ts, 0, 0)) + +} else if (v === 2) { +>v : Symbol(v, Decl(staticIndexSignature4.ts, 15, 13)) + + B.a = i.a +>B : Symbol(B, Decl(staticIndexSignature4.ts, 0, 0)) +>i : Symbol(i, Decl(staticIndexSignature4.ts, 16, 13)) + + B[2] = i[2] +>B : Symbol(B, Decl(staticIndexSignature4.ts, 0, 0)) +>i : Symbol(i, Decl(staticIndexSignature4.ts, 16, 13)) + + D.a = i.a +>D : Symbol(D, Decl(staticIndexSignature4.ts, 3, 1)) +>i : Symbol(i, Decl(staticIndexSignature4.ts, 16, 13)) + + D[2] = i [2] +>D : Symbol(D, Decl(staticIndexSignature4.ts, 3, 1)) +>i : Symbol(i, Decl(staticIndexSignature4.ts, 16, 13)) + +} else if (v === 3) { +>v : Symbol(v, Decl(staticIndexSignature4.ts, 15, 13)) + + i.a = B.a +>i : Symbol(i, Decl(staticIndexSignature4.ts, 16, 13)) +>B : Symbol(B, Decl(staticIndexSignature4.ts, 0, 0)) + + i[2] = B[2] +>i : Symbol(i, Decl(staticIndexSignature4.ts, 16, 13)) +>B : Symbol(B, Decl(staticIndexSignature4.ts, 0, 0)) + +} else if (v === 4) { +>v : Symbol(v, Decl(staticIndexSignature4.ts, 15, 13)) + + i.a = D.a +>i : Symbol(i, Decl(staticIndexSignature4.ts, 16, 13)) +>D : Symbol(D, Decl(staticIndexSignature4.ts, 3, 1)) + + i[2] = B[2] +>i : Symbol(i, Decl(staticIndexSignature4.ts, 16, 13)) +>B : Symbol(B, Decl(staticIndexSignature4.ts, 0, 0)) +} + diff --git a/tests/baselines/reference/staticIndexSignature4.types b/tests/baselines/reference/staticIndexSignature4.types new file mode 100644 index 0000000000000..ad5bfbd44cbf2 --- /dev/null +++ b/tests/baselines/reference/staticIndexSignature4.types @@ -0,0 +1,169 @@ +=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature4.ts === +class B { +>B : B + + static readonly [s: string]: number; +>s : string + + static readonly [s: number]: 42 | 233 +>s : number +} + +class D { +>D : D + + static [s: string]: number; +>s : string + + static [s: number]: 42 | 233 +>s : number +} + +interface IB { + static [s: string]: number; +>s : string + + static [s: number]: 42 | 233; +>s : number +} + +declare const v: number +>v : number + +declare const i: IB +>i : IB + +if (v === 0) { +>v === 0 : boolean +>v : number +>0 : 0 + + B.a = D.a +>B.a = D.a : number +>B.a : number +>B : typeof B +>a : number +>D.a : number +>D : typeof D +>a : number + + B[2] = D[2] +>B[2] = D[2] : 42 | 233 +>B[2] : 42 | 233 +>B : typeof B +>2 : 2 +>D[2] : 42 | 233 +>D : typeof D +>2 : 2 + +} else if (v === 1) { +>v === 1 : boolean +>v : number +>1 : 1 + + D.a = B.a +>D.a = B.a : number +>D.a : number +>D : typeof D +>a : number +>B.a : number +>B : typeof B +>a : number + + D[2] = B[2] +>D[2] = B[2] : 42 | 233 +>D[2] : 42 | 233 +>D : typeof D +>2 : 2 +>B[2] : 42 | 233 +>B : typeof B +>2 : 2 + +} else if (v === 2) { +>v === 2 : boolean +>v : number +>2 : 2 + + B.a = i.a +>B.a = i.a : number +>B.a : number +>B : typeof B +>a : number +>i.a : number +>i : IB +>a : number + + B[2] = i[2] +>B[2] = i[2] : 42 | 233 +>B[2] : 42 | 233 +>B : typeof B +>2 : 2 +>i[2] : 42 | 233 +>i : IB +>2 : 2 + + D.a = i.a +>D.a = i.a : number +>D.a : number +>D : typeof D +>a : number +>i.a : number +>i : IB +>a : number + + D[2] = i [2] +>D[2] = i [2] : 42 | 233 +>D[2] : 42 | 233 +>D : typeof D +>2 : 2 +>i [2] : 42 | 233 +>i : IB +>2 : 2 + +} else if (v === 3) { +>v === 3 : boolean +>v : number +>3 : 3 + + i.a = B.a +>i.a = B.a : number +>i.a : number +>i : IB +>a : number +>B.a : number +>B : typeof B +>a : number + + i[2] = B[2] +>i[2] = B[2] : 42 | 233 +>i[2] : 42 | 233 +>i : IB +>2 : 2 +>B[2] : 42 | 233 +>B : typeof B +>2 : 2 + +} else if (v === 4) { +>v === 4 : boolean +>v : number +>4 : 4 + + i.a = D.a +>i.a = D.a : number +>i.a : number +>i : IB +>a : number +>D.a : number +>D : typeof D +>a : number + + i[2] = B[2] +>i[2] = B[2] : 42 | 233 +>i[2] : 42 | 233 +>i : IB +>2 : 2 +>B[2] : 42 | 233 +>B : typeof B +>2 : 2 +} + diff --git a/tests/baselines/reference/staticIndexSignature5.js b/tests/baselines/reference/staticIndexSignature5.js new file mode 100644 index 0000000000000..8d2735821ad1f --- /dev/null +++ b/tests/baselines/reference/staticIndexSignature5.js @@ -0,0 +1,32 @@ +//// [staticIndexSignature5.ts] +class B { + static readonly [s: string]: number; + static readonly [s: number]: 42 | 233 +} + +interface I { + static readonly [s: string]: number; + static readonly [s: number]: 42 | 233 +} + +type TA = (typeof B)["foo"] +type TB = (typeof B)[42] + +type TC = (typeof B)[string] +type TD = (typeof B)[number] + +type TE = keyof typeof B; + +type TF = Pick +type TFI = Pick +type TG = Omit +type TGI = Omit + + +//// [staticIndexSignature5.js] +"use strict"; +var B = /** @class */ (function () { + function B() { + } + return B; +}()); diff --git a/tests/baselines/reference/staticIndexSignature5.symbols b/tests/baselines/reference/staticIndexSignature5.symbols new file mode 100644 index 0000000000000..684c403716650 --- /dev/null +++ b/tests/baselines/reference/staticIndexSignature5.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature5.ts === +class B { +>B : Symbol(B, Decl(staticIndexSignature5.ts, 0, 0)) + + static readonly [s: string]: number; +>s : Symbol(s, Decl(staticIndexSignature5.ts, 1, 21)) + + static readonly [s: number]: 42 | 233 +>s : Symbol(s, Decl(staticIndexSignature5.ts, 2, 21)) +} + +interface I { +>I : Symbol(I, Decl(staticIndexSignature5.ts, 3, 1)) + + static readonly [s: string]: number; +>s : Symbol(s, Decl(staticIndexSignature5.ts, 6, 21)) + + static readonly [s: number]: 42 | 233 +>s : Symbol(s, Decl(staticIndexSignature5.ts, 7, 21)) +} + +type TA = (typeof B)["foo"] +>TA : Symbol(TA, Decl(staticIndexSignature5.ts, 8, 1)) +>B : Symbol(B, Decl(staticIndexSignature5.ts, 0, 0)) + +type TB = (typeof B)[42] +>TB : Symbol(TB, Decl(staticIndexSignature5.ts, 10, 27)) +>B : Symbol(B, Decl(staticIndexSignature5.ts, 0, 0)) + +type TC = (typeof B)[string] +>TC : Symbol(TC, Decl(staticIndexSignature5.ts, 11, 24)) +>B : Symbol(B, Decl(staticIndexSignature5.ts, 0, 0)) + +type TD = (typeof B)[number] +>TD : Symbol(TD, Decl(staticIndexSignature5.ts, 13, 28)) +>B : Symbol(B, Decl(staticIndexSignature5.ts, 0, 0)) + +type TE = keyof typeof B; +>TE : Symbol(TE, Decl(staticIndexSignature5.ts, 14, 28)) +>B : Symbol(B, Decl(staticIndexSignature5.ts, 0, 0)) + +type TF = Pick +>TF : Symbol(TF, Decl(staticIndexSignature5.ts, 16, 25)) +>Pick : Symbol(Pick, Decl(lib.es5.d.ts, --, --)) +>B : Symbol(B, Decl(staticIndexSignature5.ts, 0, 0)) + +type TFI = Pick +>TFI : Symbol(TFI, Decl(staticIndexSignature5.ts, 18, 32)) +>Pick : Symbol(Pick, Decl(lib.es5.d.ts, --, --)) +>I : Symbol(I, Decl(staticIndexSignature5.ts, 3, 1)) + +type TG = Omit +>TG : Symbol(TG, Decl(staticIndexSignature5.ts, 19, 26)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>B : Symbol(B, Decl(staticIndexSignature5.ts, 0, 0)) + +type TGI = Omit +>TGI : Symbol(TGI, Decl(staticIndexSignature5.ts, 20, 32)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>I : Symbol(I, Decl(staticIndexSignature5.ts, 3, 1)) + diff --git a/tests/baselines/reference/staticIndexSignature5.types b/tests/baselines/reference/staticIndexSignature5.types new file mode 100644 index 0000000000000..d79848c9f29bd --- /dev/null +++ b/tests/baselines/reference/staticIndexSignature5.types @@ -0,0 +1,53 @@ +=== tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature5.ts === +class B { +>B : B + + static readonly [s: string]: number; +>s : string + + static readonly [s: number]: 42 | 233 +>s : number +} + +interface I { + static readonly [s: string]: number; +>s : string + + static readonly [s: number]: 42 | 233 +>s : number +} + +type TA = (typeof B)["foo"] +>TA : number +>B : typeof B + +type TB = (typeof B)[42] +>TB : 42 | 233 +>B : typeof B + +type TC = (typeof B)[string] +>TC : number +>B : typeof B + +type TD = (typeof B)[number] +>TD : 42 | 233 +>B : typeof B + +type TE = keyof typeof B; +>TE : string | number +>B : typeof B + +type TF = Pick +>TF : Pick +>B : typeof B + +type TFI = Pick +>TFI : Pick + +type TG = Omit +>TG : Pick +>B : typeof B + +type TGI = Omit +>TGI : Pick + diff --git a/tests/cases/compiler/staticIndexSignature1.ts b/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature1.ts similarity index 87% rename from tests/cases/compiler/staticIndexSignature1.ts rename to tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature1.ts index edc6575530feb..94e7e1f18e3bb 100644 --- a/tests/cases/compiler/staticIndexSignature1.ts +++ b/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature1.ts @@ -1,4 +1,3 @@ -// @skipLibCheck: true class C { static [s: string]: number; static [s: number]: 42 diff --git a/tests/cases/compiler/staticIndexSignature2.ts b/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts similarity index 88% rename from tests/cases/compiler/staticIndexSignature2.ts rename to tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts index 3df6c1b48da44..67a8a5cea4dd4 100644 --- a/tests/cases/compiler/staticIndexSignature2.ts +++ b/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature2.ts @@ -1,4 +1,3 @@ -// @skipLibCheck: true class C { static readonly [s: string]: number; static readonly [s: number]: 42 diff --git a/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts b/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts new file mode 100644 index 0000000000000..6ecf5f2ab9bd7 --- /dev/null +++ b/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature3.ts @@ -0,0 +1,28 @@ +// @strict: true + +class B { + static readonly [s: string]: number; + static readonly [s: number]: 42 | 233 +} + +class D extends B { + static readonly [s: string]: number +} + +class ED extends D { + static readonly [s: string]: boolean + static readonly [s: number]: 1 +} + +class DD extends D { + static readonly [s: string]: 421 +} + +const a = B["f"]; +const b = B[42]; +const c = D["f"] +const d = D[42] +const e = ED["f"] +const f = ED[42] +const g = DD["f"] +const h = DD[42] diff --git a/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature4.ts b/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature4.ts new file mode 100644 index 0000000000000..96e5553759a3c --- /dev/null +++ b/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature4.ts @@ -0,0 +1,37 @@ +// @strict: true + +class B { + static readonly [s: string]: number; + static readonly [s: number]: 42 | 233 +} + +class D { + static [s: string]: number; + static [s: number]: 42 | 233 +} + +interface IB { + static [s: string]: number; + static [s: number]: 42 | 233; +} + +declare const v: number +declare const i: IB +if (v === 0) { + B.a = D.a + B[2] = D[2] +} else if (v === 1) { + D.a = B.a + D[2] = B[2] +} else if (v === 2) { + B.a = i.a + B[2] = i[2] + D.a = i.a + D[2] = i [2] +} else if (v === 3) { + i.a = B.a + i[2] = B[2] +} else if (v === 4) { + i.a = D.a + i[2] = B[2] +} diff --git a/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature5.ts b/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature5.ts new file mode 100644 index 0000000000000..4518d54d1c9f5 --- /dev/null +++ b/tests/cases/conformance/classes/staticIndexSignature/staticIndexSignature5.ts @@ -0,0 +1,24 @@ +// @strict: true + +class B { + static readonly [s: string]: number; + static readonly [s: number]: 42 | 233 +} + +interface I { + static readonly [s: string]: number; + static readonly [s: number]: 42 | 233 +} + +type TA = (typeof B)["foo"] +type TB = (typeof B)[42] + +type TC = (typeof B)[string] +type TD = (typeof B)[number] + +type TE = keyof typeof B; + +type TF = Pick +type TFI = Pick +type TG = Omit +type TGI = Omit