|
|
|
|
|
by lifthrasiir
1709 days ago
|
|
interface Person {
[key: AllowedKeys]: unknown
}
This is one of annoying aspects of TypeScript. The following should work (in fact, this is how `Record<K, V>` is defined in lib.es5.d.ts after all): type Person = {
[key in AllowedKeys]: unknown
};
Note the switch from interface to type and `:` replaced with `in`. The point is that the `in` syntax (conceptually expanded into multiple fields) subsumes the `:` syntax (a generic type ascription) and is only available as a mapped type, which is distinct with an interface type. The error message does mention this, but if you don't know what is the mapped type you are left with no clues. |
|