Skip to content

Commit 16db880

Browse files
committed
Reduce test case
1 parent b93892a commit 16db880

File tree

5 files changed

+21
-38
lines changed

5 files changed

+21
-38
lines changed

tests/baselines/reference/constContextTemplateLiteral.errors.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
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; }'.
1+
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; }'.
22
Object literal may only specify known properties, and 'b' does not exist in type '{ a: any; }'.
3-
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; }'.
3+
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; }'.
44
Object literal may only specify known properties, and 'b' does not exist in type '{ a: any; }'.
55

66

@@ -13,7 +13,6 @@ tests/cases/conformance/expressions/literals/constContextTemplateLiteral.ts(11,3
1313
declare function key(): `person-${number}`
1414
/* This only happens if index type is a template literal type */
1515
const persons: Record<`person-${Person["id"]}`, { a: any }> = {
16-
...{},
1716
[`person-${1}`]: { b: "something" }, // ok, error
1817
~~~~~~~~~~~~~~
1918
!!! 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
2221
~~~~~~~~~~~~~~
2322
!!! error TS2418: Type of computed property's value is '{ b: string; }', which is not assignable to type '{ a: any; }'.
2423
!!! error TS2418: Object literal may only specify known properties, and 'b' does not exist in type '{ a: any; }'.
25-
[key()]: { b: "something" }, // still no error
24+
[key()]: { b: "something" }, // still no error, it's not a literal
2625
}
2726

tests/baselines/reference/constContextTemplateLiteral.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,17 @@ interface Person {
77
declare function key(): `person-${number}`
88
/* This only happens if index type is a template literal type */
99
const persons: Record<`person-${Person["id"]}`, { a: any }> = {
10-
...{},
1110
[`person-${1}`]: { b: "something" }, // ok, error
1211
[`person-${1}` as const]: { b: "something" }, // ok, error
13-
[key()]: { b: "something" }, // still no error
12+
[key()]: { b: "something" }, // still no error, it's not a literal
1413
}
1514

1615

1716
//// [constContextTemplateLiteral.js]
18-
var __assign = (this && this.__assign) || function () {
19-
__assign = Object.assign || function(t) {
20-
for (var s, i = 1, n = arguments.length; i < n; i++) {
21-
s = arguments[i];
22-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
23-
t[p] = s[p];
24-
}
25-
return t;
26-
};
27-
return __assign.apply(this, arguments);
28-
};
2917
var _a;
3018
/* This only happens if index type is a template literal type */
31-
var persons = __assign({}, (_a = {}, _a["person-".concat(1)] = { b: "something" }, _a["person-".concat(1)] = { b: "something" }, _a[key()] = { b: "something" }, _a));
19+
var persons = (_a = {},
20+
_a["person-".concat(1)] = { b: "something" },
21+
_a["person-".concat(1)] = { b: "something" },
22+
_a[key()] = { b: "something" },
23+
_a);

tests/baselines/reference/constContextTemplateLiteral.symbols

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,18 @@ const persons: Record<`person-${Person["id"]}`, { a: any }> = {
1919
>Person : Symbol(Person, Decl(constContextTemplateLiteral.ts, 0, 0))
2020
>a : Symbol(a, Decl(constContextTemplateLiteral.ts, 7, 49))
2121

22-
...{},
2322
[`person-${1}`]: { b: "something" }, // ok, error
24-
>[`person-${1}`] : Symbol([`person-${1}`], Decl(constContextTemplateLiteral.ts, 8, 10))
25-
>b : Symbol(b, Decl(constContextTemplateLiteral.ts, 9, 22))
23+
>[`person-${1}`] : Symbol([`person-${1}`], Decl(constContextTemplateLiteral.ts, 7, 63))
24+
>b : Symbol(b, Decl(constContextTemplateLiteral.ts, 8, 22))
2625

2726
[`person-${1}` as const]: { b: "something" }, // ok, error
28-
>[`person-${1}` as const] : Symbol([`person-${1}` as const], Decl(constContextTemplateLiteral.ts, 9, 40))
27+
>[`person-${1}` as const] : Symbol([`person-${1}` as const], Decl(constContextTemplateLiteral.ts, 8, 40))
2928
>const : Symbol(const)
30-
>b : Symbol(b, Decl(constContextTemplateLiteral.ts, 10, 31))
29+
>b : Symbol(b, Decl(constContextTemplateLiteral.ts, 9, 31))
3130

32-
[key()]: { b: "something" }, // still no error
33-
>[key()] : Symbol([key()], Decl(constContextTemplateLiteral.ts, 10, 49))
31+
[key()]: { b: "something" }, // still no error, it's not a literal
32+
>[key()] : Symbol([key()], Decl(constContextTemplateLiteral.ts, 9, 49))
3433
>key : Symbol(key, Decl(constContextTemplateLiteral.ts, 3, 1))
35-
>b : Symbol(b, Decl(constContextTemplateLiteral.ts, 11, 14))
34+
>b : Symbol(b, Decl(constContextTemplateLiteral.ts, 10, 14))
3635
}
3736

tests/baselines/reference/constContextTemplateLiteral.types

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ declare function key(): `person-${number}`
1414
const persons: Record<`person-${Person["id"]}`, { a: any }> = {
1515
>persons : Record<`person-${number}`, { a: any; }>
1616
>a : any
17-
>{ ...{}, [`person-${1}`]: { b: "something" }, // ok, error [`person-${1}` as const]: { b: "something" }, // ok, error [key()]: { b: "something" }, // still no error} : { "person-1": { b: string; }; }
18-
19-
...{},
20-
>{} : {}
17+
>{ [`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; }; }
2118

2219
[`person-${1}`]: { b: "something" }, // ok, error
2320
>[`person-${1}`] : { b: string; }
@@ -36,7 +33,7 @@ const persons: Record<`person-${Person["id"]}`, { a: any }> = {
3633
>b : string
3734
>"something" : "something"
3835

39-
[key()]: { b: "something" }, // still no error
36+
[key()]: { b: "something" }, // still no error, it's not a literal
4037
>[key()] : { b: string; }
4138
>key() : `person-${number}`
4239
>key : () => `person-${number}`
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
interface Person {
2-
id: number;
3-
name: string;
4-
}
1+
type Person = { id: number }
52

63
declare function key(): `person-${number}`
74
/* This only happens if index type is a template literal type */
85
const persons: Record<`person-${Person["id"]}`, { a: any }> = {
9-
...{},
106
[`person-${1}`]: { b: "something" }, // ok, error
11-
[`person-${1}` as const]: { b: "something" }, // ok, error
12-
[key()]: { b: "something" }, // still no error
7+
// [`person-${1}` as const]: { b: "something" }, // ok, error
8+
// [key()]: { b: "something" }, // still no error, it's not a literal
139
}

0 commit comments

Comments
 (0)