From ea7d4c62c992bba84dca989fc8570159d86be72a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 21 Oct 2021 11:10:04 -0700 Subject: [PATCH] Reduce test case + update baselines --- .../computedPropertyNames10_ES5.types | 2 +- .../computedPropertyNames10_ES6.types | 2 +- .../computedPropertyNames11_ES5.types | 2 +- .../computedPropertyNames11_ES6.types | 2 +- .../computedPropertyNames12_ES5.types | 2 +- .../computedPropertyNames12_ES6.types | 2 +- .../computedPropertyNames13_ES5.types | 2 +- .../computedPropertyNames13_ES6.types | 2 +- .../computedPropertyNames14_ES5.types | 2 +- .../computedPropertyNames14_ES6.types | 2 +- .../computedPropertyNames16_ES5.types | 2 +- .../computedPropertyNames16_ES6.types | 2 +- .../computedPropertyNames17_ES5.types | 2 +- .../computedPropertyNames17_ES6.types | 2 +- .../computedPropertyNames3_ES5.types | 2 +- .../computedPropertyNames3_ES6.types | 2 +- .../computedPropertyNames4_ES5.types | 2 +- .../computedPropertyNames4_ES6.types | 2 +- .../computedPropertyNames5_ES5.types | 2 +- .../computedPropertyNames5_ES6.types | 2 +- .../constContextTemplateLiteral.errors.txt | 21 +++-------- .../reference/constContextTemplateLiteral.js | 15 ++------ .../constContextTemplateLiteral.symbols | 35 ++++--------------- .../constContextTemplateLiteral.types | 35 +++---------------- .../literals/constContextTemplateLiteral.ts | 7 +--- 25 files changed, 39 insertions(+), 114 deletions(-) diff --git a/tests/baselines/reference/computedPropertyNames10_ES5.types b/tests/baselines/reference/computedPropertyNames10_ES5.types index 82d82bcc63..7c89309b32 100644 --- a/tests/baselines/reference/computedPropertyNames10_ES5.types +++ b/tests/baselines/reference/computedPropertyNames10_ES5.types @@ -60,6 +60,6 @@ var v = { [`hello ${a} bye`]() { } >[`hello ${a} bye`] : () => void ->`hello ${a} bye` : string +>`hello ${a} bye` : `hello ${any} bye` >a : any } diff --git a/tests/baselines/reference/computedPropertyNames10_ES6.types b/tests/baselines/reference/computedPropertyNames10_ES6.types index c9ad6eeebb..355fc7c582 100644 --- a/tests/baselines/reference/computedPropertyNames10_ES6.types +++ b/tests/baselines/reference/computedPropertyNames10_ES6.types @@ -60,6 +60,6 @@ var v = { [`hello ${a} bye`]() { } >[`hello ${a} bye`] : () => void ->`hello ${a} bye` : string +>`hello ${a} bye` : `hello ${any} bye` >a : any } diff --git a/tests/baselines/reference/computedPropertyNames11_ES5.types b/tests/baselines/reference/computedPropertyNames11_ES5.types index 944f4a4cfc..b66b419310 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES5.types +++ b/tests/baselines/reference/computedPropertyNames11_ES5.types @@ -70,7 +70,7 @@ var v = { get [`hello ${a} bye`]() { return 0; } >[`hello ${a} bye`] : number ->`hello ${a} bye` : string +>`hello ${a} bye` : `hello ${any} bye` >a : any >0 : 0 } diff --git a/tests/baselines/reference/computedPropertyNames11_ES6.types b/tests/baselines/reference/computedPropertyNames11_ES6.types index 1d9551ea08..40e0c98488 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES6.types +++ b/tests/baselines/reference/computedPropertyNames11_ES6.types @@ -70,7 +70,7 @@ var v = { get [`hello ${a} bye`]() { return 0; } >[`hello ${a} bye`] : number ->`hello ${a} bye` : string +>`hello ${a} bye` : `hello ${any} bye` >a : any >0 : 0 } diff --git a/tests/baselines/reference/computedPropertyNames12_ES5.types b/tests/baselines/reference/computedPropertyNames12_ES5.types index 63afc3bd4d..cc7d1a2975 100644 --- a/tests/baselines/reference/computedPropertyNames12_ES5.types +++ b/tests/baselines/reference/computedPropertyNames12_ES5.types @@ -63,7 +63,7 @@ class C { static [`hello ${a} bye`] = 0 >[`hello ${a} bye`] : number ->`hello ${a} bye` : string +>`hello ${a} bye` : `hello ${any} bye` >a : any >0 : 0 } diff --git a/tests/baselines/reference/computedPropertyNames12_ES6.types b/tests/baselines/reference/computedPropertyNames12_ES6.types index f846d159ee..d1da7d7aab 100644 --- a/tests/baselines/reference/computedPropertyNames12_ES6.types +++ b/tests/baselines/reference/computedPropertyNames12_ES6.types @@ -63,7 +63,7 @@ class C { static [`hello ${a} bye`] = 0 >[`hello ${a} bye`] : number ->`hello ${a} bye` : string +>`hello ${a} bye` : `hello ${any} bye` >a : any >0 : 0 } diff --git a/tests/baselines/reference/computedPropertyNames13_ES5.types b/tests/baselines/reference/computedPropertyNames13_ES5.types index 07c5cee22c..33c89a82c9 100644 --- a/tests/baselines/reference/computedPropertyNames13_ES5.types +++ b/tests/baselines/reference/computedPropertyNames13_ES5.types @@ -59,6 +59,6 @@ class C { static [`hello ${a} bye`]() { } >[`hello ${a} bye`] : () => void ->`hello ${a} bye` : string +>`hello ${a} bye` : `hello ${any} bye` >a : any } diff --git a/tests/baselines/reference/computedPropertyNames13_ES6.types b/tests/baselines/reference/computedPropertyNames13_ES6.types index 8e0111d760..57a4bb9b46 100644 --- a/tests/baselines/reference/computedPropertyNames13_ES6.types +++ b/tests/baselines/reference/computedPropertyNames13_ES6.types @@ -59,6 +59,6 @@ class C { static [`hello ${a} bye`]() { } >[`hello ${a} bye`] : () => void ->`hello ${a} bye` : string +>`hello ${a} bye` : `hello ${any} bye` >a : any } diff --git a/tests/baselines/reference/computedPropertyNames14_ES5.types b/tests/baselines/reference/computedPropertyNames14_ES5.types index c0b5ddcd5a..54ca3b9d11 100644 --- a/tests/baselines/reference/computedPropertyNames14_ES5.types +++ b/tests/baselines/reference/computedPropertyNames14_ES5.types @@ -15,7 +15,7 @@ class C { [[]]() { } >[[]] : () => void ->[] : undefined[] +>[] : readonly [] static [{}]() { } >[{}] : () => void diff --git a/tests/baselines/reference/computedPropertyNames14_ES6.types b/tests/baselines/reference/computedPropertyNames14_ES6.types index 2c3d7dc2ad..04455a7d63 100644 --- a/tests/baselines/reference/computedPropertyNames14_ES6.types +++ b/tests/baselines/reference/computedPropertyNames14_ES6.types @@ -15,7 +15,7 @@ class C { [[]]() { } >[[]] : () => void ->[] : undefined[] +>[] : readonly [] static [{}]() { } >[{}] : () => void diff --git a/tests/baselines/reference/computedPropertyNames16_ES5.types b/tests/baselines/reference/computedPropertyNames16_ES5.types index 7e6d505409..468f77b322 100644 --- a/tests/baselines/reference/computedPropertyNames16_ES5.types +++ b/tests/baselines/reference/computedPropertyNames16_ES5.types @@ -69,7 +69,7 @@ class C { get [`hello ${a} bye`]() { return 0; } >[`hello ${a} bye`] : number ->`hello ${a} bye` : string +>`hello ${a} bye` : `hello ${any} bye` >a : any >0 : 0 } diff --git a/tests/baselines/reference/computedPropertyNames16_ES6.types b/tests/baselines/reference/computedPropertyNames16_ES6.types index 9898cbc00d..558af27cea 100644 --- a/tests/baselines/reference/computedPropertyNames16_ES6.types +++ b/tests/baselines/reference/computedPropertyNames16_ES6.types @@ -69,7 +69,7 @@ class C { get [`hello ${a} bye`]() { return 0; } >[`hello ${a} bye`] : number ->`hello ${a} bye` : string +>`hello ${a} bye` : `hello ${any} bye` >a : any >0 : 0 } diff --git a/tests/baselines/reference/computedPropertyNames17_ES5.types b/tests/baselines/reference/computedPropertyNames17_ES5.types index f1a2895771..e53bac2f06 100644 --- a/tests/baselines/reference/computedPropertyNames17_ES5.types +++ b/tests/baselines/reference/computedPropertyNames17_ES5.types @@ -17,7 +17,7 @@ class C { get [[]]() { return 0; } >[[]] : number ->[] : undefined[] +>[] : readonly [] >0 : 0 set [{}](v) { } diff --git a/tests/baselines/reference/computedPropertyNames17_ES6.types b/tests/baselines/reference/computedPropertyNames17_ES6.types index e8b700ce00..c957894564 100644 --- a/tests/baselines/reference/computedPropertyNames17_ES6.types +++ b/tests/baselines/reference/computedPropertyNames17_ES6.types @@ -17,7 +17,7 @@ class C { get [[]]() { return 0; } >[[]] : number ->[] : undefined[] +>[] : readonly [] >0 : 0 set [{}](v) { } diff --git a/tests/baselines/reference/computedPropertyNames3_ES5.types b/tests/baselines/reference/computedPropertyNames3_ES5.types index 5657568db7..0e392fca39 100644 --- a/tests/baselines/reference/computedPropertyNames3_ES5.types +++ b/tests/baselines/reference/computedPropertyNames3_ES5.types @@ -22,7 +22,7 @@ class C { set [[0, 1]](v) { } >[[0, 1]] : any ->[0, 1] : number[] +>[0, 1] : readonly [0, 1] >0 : 0 >1 : 1 >v : any diff --git a/tests/baselines/reference/computedPropertyNames3_ES6.types b/tests/baselines/reference/computedPropertyNames3_ES6.types index 710f852e0f..e4748a9b7c 100644 --- a/tests/baselines/reference/computedPropertyNames3_ES6.types +++ b/tests/baselines/reference/computedPropertyNames3_ES6.types @@ -22,7 +22,7 @@ class C { set [[0, 1]](v) { } >[[0, 1]] : any ->[0, 1] : number[] +>[0, 1] : readonly [0, 1] >0 : 0 >1 : 1 >v : any diff --git a/tests/baselines/reference/computedPropertyNames4_ES5.types b/tests/baselines/reference/computedPropertyNames4_ES5.types index b9181140ed..ba6d3c6d9e 100644 --- a/tests/baselines/reference/computedPropertyNames4_ES5.types +++ b/tests/baselines/reference/computedPropertyNames4_ES5.types @@ -70,7 +70,7 @@ var v = { [`hello ${a} bye`]: 0 >[`hello ${a} bye`] : number ->`hello ${a} bye` : string +>`hello ${a} bye` : `hello ${any} bye` >a : any >0 : 0 } diff --git a/tests/baselines/reference/computedPropertyNames4_ES6.types b/tests/baselines/reference/computedPropertyNames4_ES6.types index 669af26ebd..a25ca0f7bc 100644 --- a/tests/baselines/reference/computedPropertyNames4_ES6.types +++ b/tests/baselines/reference/computedPropertyNames4_ES6.types @@ -70,7 +70,7 @@ var v = { [`hello ${a} bye`]: 0 >[`hello ${a} bye`] : number ->`hello ${a} bye` : string +>`hello ${a} bye` : `hello ${any} bye` >a : any >0 : 0 } diff --git a/tests/baselines/reference/computedPropertyNames5_ES5.types b/tests/baselines/reference/computedPropertyNames5_ES5.types index 64b51175c3..f7452b738e 100644 --- a/tests/baselines/reference/computedPropertyNames5_ES5.types +++ b/tests/baselines/reference/computedPropertyNames5_ES5.types @@ -18,7 +18,7 @@ var v = { [[]]: 0, >[[]] : number ->[] : undefined[] +>[] : readonly [] >0 : 0 [{}]: 0, diff --git a/tests/baselines/reference/computedPropertyNames5_ES6.types b/tests/baselines/reference/computedPropertyNames5_ES6.types index 5ffcba5cbc..fd0f3ca049 100644 --- a/tests/baselines/reference/computedPropertyNames5_ES6.types +++ b/tests/baselines/reference/computedPropertyNames5_ES6.types @@ -18,7 +18,7 @@ var v = { [[]]: 0, >[[]] : number ->[] : undefined[] +>[] : readonly [] >0 : 0 [{}]: 0, diff --git a/tests/baselines/reference/constContextTemplateLiteral.errors.txt b/tests/baselines/reference/constContextTemplateLiteral.errors.txt index 16a91c79d8..a5f8e26031 100644 --- a/tests/baselines/reference/constContextTemplateLiteral.errors.txt +++ b/tests/baselines/reference/constContextTemplateLiteral.errors.txt @@ -1,26 +1,13 @@ -tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts(9,24): error TS2418: Type of computed property's value is '{ b: string; }', which is not assignable to type '{ a: any; }'. - Object literal may only specify known properties, and 'b' does not exist in type '{ a: any; }'. -tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts(10,33): error TS2418: Type of computed property's value is '{ b: string; }', which is not assignable to type '{ a: any; }'. +tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts(3,24): error TS2418: Type of computed property's value is '{ b: string; }', which is not assignable to type '{ a: any; }'. Object literal may only specify known properties, and 'b' does not exist in type '{ a: any; }'. -==== tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts (2 errors) ==== - interface Person { - id: number; - name: string; - } - - declare function key(): `person-${number}` - /* This only happens if index type is a template literal type */ - const persons: Record<`person-${Person["id"]}`, { a: any }> = { +==== tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts (1 errors) ==== + type Person = { id: number } + const persons: Record = { [`person-${1}`]: { b: "something" }, // ok, error ~~~~~~~~~~~~~~ !!! error TS2418: Type of computed property's value is '{ b: string; }', which is not assignable to type '{ a: any; }'. !!! error TS2418: Object literal may only specify known properties, and 'b' does not exist in type '{ a: any; }'. - [`person-${1}` as const]: { b: "something" }, // ok, error - ~~~~~~~~~~~~~~ -!!! error TS2418: Type of computed property's value is '{ b: string; }', which is not assignable to type '{ a: any; }'. -!!! error TS2418: Object literal may only specify known properties, and 'b' does not exist in type '{ a: any; }'. - [key()]: { b: "something" }, // still no error, it's not a literal } \ No newline at end of file diff --git a/tests/baselines/reference/constContextTemplateLiteral.js b/tests/baselines/reference/constContextTemplateLiteral.js index ee69334866..f1936dcd96 100644 --- a/tests/baselines/reference/constContextTemplateLiteral.js +++ b/tests/baselines/reference/constContextTemplateLiteral.js @@ -1,23 +1,12 @@ //// [constContextTemplateLiteral.ts] -interface Person { - id: number; - name: string; -} - -declare function key(): `person-${number}` -/* This only happens if index type is a template literal type */ -const persons: Record<`person-${Person["id"]}`, { a: any }> = { +type Person = { id: number } +const persons: Record = { [`person-${1}`]: { b: "something" }, // ok, error - [`person-${1}` as const]: { b: "something" }, // ok, error - [key()]: { b: "something" }, // still no error, it's not a literal } //// [constContextTemplateLiteral.js] var _a; -/* This only happens if index type is a template literal type */ var persons = (_a = {}, _a["person-".concat(1)] = { b: "something" }, - _a["person-".concat(1)] = { b: "something" }, - _a[key()] = { b: "something" }, _a); diff --git a/tests/baselines/reference/constContextTemplateLiteral.symbols b/tests/baselines/reference/constContextTemplateLiteral.symbols index 4349fba95f..e82b2ec629 100644 --- a/tests/baselines/reference/constContextTemplateLiteral.symbols +++ b/tests/baselines/reference/constContextTemplateLiteral.symbols @@ -1,36 +1,15 @@ === tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts === -interface Person { +type Person = { id: number } >Person : Symbol(Person, Decl(constContextTemplateLiteral.ts, 0, 0)) +>id : Symbol(id, Decl(constContextTemplateLiteral.ts, 0, 15)) - id: number; ->id : Symbol(Person.id, Decl(constContextTemplateLiteral.ts, 0, 18)) - - name: string; ->name : Symbol(Person.name, Decl(constContextTemplateLiteral.ts, 1, 15)) -} - -declare function key(): `person-${number}` ->key : Symbol(key, Decl(constContextTemplateLiteral.ts, 3, 1)) - -/* This only happens if index type is a template literal type */ -const persons: Record<`person-${Person["id"]}`, { a: any }> = { ->persons : Symbol(persons, Decl(constContextTemplateLiteral.ts, 7, 5)) +const persons: Record = { +>persons : Symbol(persons, Decl(constContextTemplateLiteral.ts, 1, 5)) >Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) ->Person : Symbol(Person, Decl(constContextTemplateLiteral.ts, 0, 0)) ->a : Symbol(a, Decl(constContextTemplateLiteral.ts, 7, 49)) +>a : Symbol(a, Decl(constContextTemplateLiteral.ts, 1, 31)) [`person-${1}`]: { b: "something" }, // ok, error ->[`person-${1}`] : Symbol([`person-${1}`], Decl(constContextTemplateLiteral.ts, 7, 63)) ->b : Symbol(b, Decl(constContextTemplateLiteral.ts, 8, 22)) - - [`person-${1}` as const]: { b: "something" }, // ok, error ->[`person-${1}` as const] : Symbol([`person-${1}` as const], Decl(constContextTemplateLiteral.ts, 8, 40)) ->const : Symbol(const) ->b : Symbol(b, Decl(constContextTemplateLiteral.ts, 9, 31)) - - [key()]: { b: "something" }, // still no error, it's not a literal ->[key()] : Symbol([key()], Decl(constContextTemplateLiteral.ts, 9, 49)) ->key : Symbol(key, Decl(constContextTemplateLiteral.ts, 3, 1)) ->b : Symbol(b, Decl(constContextTemplateLiteral.ts, 10, 14)) +>[`person-${1}`] : Symbol([`person-${1}`], Decl(constContextTemplateLiteral.ts, 1, 45)) +>b : Symbol(b, Decl(constContextTemplateLiteral.ts, 2, 22)) } diff --git a/tests/baselines/reference/constContextTemplateLiteral.types b/tests/baselines/reference/constContextTemplateLiteral.types index 7d269bb604..7868cb9950 100644 --- a/tests/baselines/reference/constContextTemplateLiteral.types +++ b/tests/baselines/reference/constContextTemplateLiteral.types @@ -1,20 +1,12 @@ === tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts === -interface Person { - id: number; +type Person = { id: number } +>Person : Person >id : number - name: string; ->name : string -} - -declare function key(): `person-${number}` ->key : () => `person-${number}` - -/* This only happens if index type is a template literal type */ -const persons: Record<`person-${Person["id"]}`, { a: any }> = { ->persons : Record<`person-${number}`, { a: any; }> +const persons: Record = { +>persons : Record >a : any ->{ [`person-${1}`]: { b: "something" }, // ok, error [`person-${1}` as const]: { b: "something" }, // ok, error [key()]: { b: "something" }, // still no error, it's not a literal} : { [x: string]: { b: string; }; "person-1": { b: string; }; } +>{ [`person-${1}`]: { b: "something" }, // ok, error} : { "person-1": { b: string; }; } [`person-${1}`]: { b: "something" }, // ok, error >[`person-${1}`] : { b: string; } @@ -22,23 +14,6 @@ const persons: Record<`person-${Person["id"]}`, { a: any }> = { >1 : 1 >{ b: "something" } : { b: string; } >b : string ->"something" : "something" - - [`person-${1}` as const]: { b: "something" }, // ok, error ->[`person-${1}` as const] : { b: string; } ->`person-${1}` as const : "person-1" ->`person-${1}` : "person-1" ->1 : 1 ->{ b: "something" } : { b: string; } ->b : string ->"something" : "something" - - [key()]: { b: "something" }, // still no error, it's not a literal ->[key()] : { b: string; } ->key() : `person-${number}` ->key : () => `person-${number}` ->{ b: "something" } : { b: string; } ->b : string >"something" : "something" } diff --git a/tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts b/tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts index 256610fd7d..b870b8c760 100644 --- a/tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts +++ b/tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts @@ -1,9 +1,4 @@ type Person = { id: number } - -declare function key(): `person-${number}` -/* This only happens if index type is a template literal type */ -const persons: Record<`person-${Person["id"]}`, { a: any }> = { +const persons: Record = { [`person-${1}`]: { b: "something" }, // ok, error - // [`person-${1}` as const]: { b: "something" }, // ok, error - // [key()]: { b: "something" }, // still no error, it's not a literal }