diff --git a/tests/baselines/reference/constContextTemplateLiteral.errors.txt b/tests/baselines/reference/constContextTemplateLiteral.errors.txt index 2f084fda02..16a91c79d8 100644 --- a/tests/baselines/reference/constContextTemplateLiteral.errors.txt +++ b/tests/baselines/reference/constContextTemplateLiteral.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts(10,24): 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(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(11,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(10,33): 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; }'. @@ -13,7 +13,6 @@ tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts(11,3 declare function key(): `person-${number}` /* This only happens if index type is a template literal type */ const persons: Record<`person-${Person["id"]}`, { a: any }> = { - ...{}, [`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; }'. @@ -22,6 +21,6 @@ tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts(11,3 ~~~~~~~~~~~~~~ !!! 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 + [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 10f4d01362..ee69334866 100644 --- a/tests/baselines/reference/constContextTemplateLiteral.js +++ b/tests/baselines/reference/constContextTemplateLiteral.js @@ -7,25 +7,17 @@ interface Person { declare function key(): `person-${number}` /* This only happens if index type is a template literal type */ const persons: Record<`person-${Person["id"]}`, { a: any }> = { - ...{}, [`person-${1}`]: { b: "something" }, // ok, error [`person-${1}` as const]: { b: "something" }, // ok, error - [key()]: { b: "something" }, // still no error + [key()]: { b: "something" }, // still no error, it's not a literal } //// [constContextTemplateLiteral.js] -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; var _a; /* This only happens if index type is a template literal type */ -var persons = __assign({}, (_a = {}, _a["person-".concat(1)] = { b: "something" }, _a["person-".concat(1)] = { b: "something" }, _a[key()] = { b: "something" }, _a)); +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 2d31f131f2..4349fba95f 100644 --- a/tests/baselines/reference/constContextTemplateLiteral.symbols +++ b/tests/baselines/reference/constContextTemplateLiteral.symbols @@ -19,19 +19,18 @@ const persons: Record<`person-${Person["id"]}`, { a: any }> = { >Person : Symbol(Person, Decl(constContextTemplateLiteral.ts, 0, 0)) >a : Symbol(a, Decl(constContextTemplateLiteral.ts, 7, 49)) - ...{}, [`person-${1}`]: { b: "something" }, // ok, error ->[`person-${1}`] : Symbol([`person-${1}`], Decl(constContextTemplateLiteral.ts, 8, 10)) ->b : Symbol(b, Decl(constContextTemplateLiteral.ts, 9, 22)) +>[`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, 9, 40)) +>[`person-${1}` as const] : Symbol([`person-${1}` as const], Decl(constContextTemplateLiteral.ts, 8, 40)) >const : Symbol(const) ->b : Symbol(b, Decl(constContextTemplateLiteral.ts, 10, 31)) +>b : Symbol(b, Decl(constContextTemplateLiteral.ts, 9, 31)) - [key()]: { b: "something" }, // still no error ->[key()] : Symbol([key()], Decl(constContextTemplateLiteral.ts, 10, 49)) + [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, 11, 14)) +>b : Symbol(b, Decl(constContextTemplateLiteral.ts, 10, 14)) } diff --git a/tests/baselines/reference/constContextTemplateLiteral.types b/tests/baselines/reference/constContextTemplateLiteral.types index 99fcfb91c1..7d269bb604 100644 --- a/tests/baselines/reference/constContextTemplateLiteral.types +++ b/tests/baselines/reference/constContextTemplateLiteral.types @@ -14,10 +14,7 @@ declare function key(): `person-${number}` const persons: Record<`person-${Person["id"]}`, { a: any }> = { >persons : Record<`person-${number}`, { a: any; }> >a : any ->{ ...{}, [`person-${1}`]: { b: "something" }, // ok, error [`person-${1}` as const]: { b: "something" }, // ok, error [key()]: { b: "something" }, // still no error} : { "person-1": { b: string; }; } - - ...{}, ->{} : {} +>{ [`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; } @@ -36,7 +33,7 @@ const persons: Record<`person-${Person["id"]}`, { a: any }> = { >b : string >"something" : "something" - [key()]: { b: "something" }, // still no error + [key()]: { b: "something" }, // still no error, it's not a literal >[key()] : { b: string; } >key() : `person-${number}` >key : () => `person-${number}` diff --git a/tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts b/tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts index c40bc2bbad..256610fd7d 100644 --- a/tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts +++ b/tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts @@ -1,13 +1,9 @@ -interface Person { - id: number; - name: string; -} +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 }> = { - ...{}, [`person-${1}`]: { b: "something" }, // ok, error - [`person-${1}` as const]: { b: "something" }, // ok, error - [key()]: { b: "something" }, // still no error + // [`person-${1}` as const]: { b: "something" }, // ok, error + // [key()]: { b: "something" }, // still no error, it's not a literal }