Keyof inferring string | number when key is only a string

前端 未结 2 465
孤街浪徒
孤街浪徒 2020-12-01 10:02

I define an AbstractModel like so:

export interface AbstractModel {
   [key: string]: any
}

Then I declare the type Keys

2条回答
  •  伪装坚强ぢ
    2020-12-01 11:00

    I have faced similar problem. I resolved it by enforcing key to be string:

    export type Keys = keyof AbstractModel & string;
    

    Other option would be to convert key to string: test.toString().toLowercase()

提交回复
热议问题