Typescript WTF Moments 3: Type of Key is `string` if Key is Template Literal `a/${string}`
Acid Coder

Acid Coder @tylim88

About: Who needs meth when you have Typescript?

Joined:
Oct 31, 2021

Typescript WTF Moments 3: Type of Key is `string` if Key is Template Literal `a/${string}`

Publish Date: Aug 8 '22
3 0
const a = 'a'
const obj = { [a]:1 } // {a:1}

const b = 'b/a' as `b/${string}`
const obj2 = { [b]:1 } // {[x:string]:1}, expecting {[x:`b/${string}`]:1}
Enter fullscreen mode Exit fullscreen mode

playground

this is a known widen string deficiency

it is part of this long going issue

Comments 0 total

    Add comment