Preview:```ts
type R = Record<number, string>
type T = ${number}
const t1: T = ".2"
const t2 = ".2" as const
const r: R = {
[t1]: "abc",
[t2]: "abc",
}```
8 messages · Page 1 of 1 (latest)
Preview:```ts
type R = Record<number, string>
type T = ${number}
const t1: T = ".2"
const t2 = ".2" as const
const r: R = {
[t1]: "abc",
[t2]: "abc",
}```
this doesn't really help, but it's not an issue specific to template literals btw, here's an example with a plain old string
Preview:```ts
const x: string = "asdf"
const r: Record<number, string> = {
[x]: "def",
}```
I think the most likely explanation is something to do with the symbol type and how passing a variable name between [ ] on an object treats the text between the brackets as a symbol and not whatever type it was originally
cause it only occurs when it's a variable name between the [ ]
Preview:```ts
const x: string = "abc"
const r: Record<number, string> = {
[x]: "foo",
["def"]: "bar",
}
const s: Record<number, string> = {
[x]: "foo",
def: "bar",
}```
passing a variable name between
[ ]on an object treats the text between the brackets as a symbol and not whatever type it was originally
that's not correct (at least if you're talking about the JS primitive namedsymbol).{ ['a']: 1 }and{ a: 1 }produce the same object at runtime
[ ]: (computed property names) just lets you write expressions to specify keys rather than being limited to bare identifiers or strings