Closed as not planned
Description
π Search Terms
dynamic key type
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about dynamic keys
β― Playground Link
π» Code
function example1<K extends string>(key: K, value: unknown): { [key in K]: unknown }
{
return { [key]: value };
}
function example2<K extends string>(key: K, value: unknown): Record<K, unknown>
{
return { [key]: value };
}
π Actual behavior
Type '{ [x: string]: unknown; }' is not assignable to type '{ [key in K]: unknown; }'.(2322)
Type '{ [x: string]: unknown; }' is not assignable to type 'Record<K, unknown>'.(2322)
The type of the key is K but reverts to string
π Expected behavior
The type of the key is preserved as K.
Additional information about the issue
No response