type Test<T extends string, V extends unknown> = {
[Key: T]: V;
}
type Test<T extends string, V extends unknown> = {
[Key in T]: V;
}
From the code above, T extends string,why T can not be used as Key's type and it output an error An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead. But if replace Key: T with Key in T, it works.
I think what you're looking for in TypeScript is called Utility Type - Record
For example:
type Test<T extends string, V extends unknown> = Record<T, V>;
Docs: https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type