If I wrote [key: string]: string
they both work. I am curious why interface is not working when I use in
keyword here?
type Keys = "username" | "password" | "confirm" | "captcha";
export interface InputData {
[key in Keys]: string; //no good
}
export type InputData2 = {
[key in Keys]: string; //good
}
Here is the error:
A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type.ts(1169)
A computed property name must be of type 'string', 'number', 'symbol', or 'any'.ts(2464)
'Keys' only refers to a type, but is being used as a value here.ts(2693)
any