Reduce test case

This commit is contained in:
Nathan Shively-Sanders 2021-10-21 08:43:22 -07:00
parent b93892a6f3
commit 16db880e02
5 changed files with 21 additions and 38 deletions

View file

@ -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
}

View file

@ -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);

View file

@ -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))
}

View file

@ -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}`

View file

@ -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
}