【发布时间】:2019-01-19 08:20:24
【问题描述】:
我这样定义AbstractModel:
export interface AbstractModel {
[key: string]: any
}
然后我声明类型Keys:
export type Keys = keyof AbstractModel;
我希望任何具有 Keys 类型的东西都会被明确地解释为字符串,例如:
const test: Keys;
test.toLowercase(); // Error: Property 'toLowerCase' does not exist on type 'string | number'. Property 'toLowerCase' does not exist on type 'number'.
这是 Typescript (2.9.2) 的错误,还是我遗漏了什么?
【问题讨论】:
标签: typescript typescript-typings