DEV Community

Acid Coder
Acid Coder

Posted on • Edited on

1 1

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

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

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay