Consider this code:
type T<A> = {
[A]: true
}
Given this type, I would like to use it like this:
type Obj = T<"key">
To produce type equivalent to this type:
type Obj = {
key: true
}
But, the compiler is giving me this error:
A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.ts(1170)
Can I somehow prove, that the A
type variable can only by a string literal? Something like:
type T<A extends ?literal?> = {
[A]: true
}
Record<"key", true>
what you want ? – Titian Cernicova-Dragomir