【发布时间】:2021-10-06 08:33:50
【问题描述】:
我有一个像下面这样的类型,如何为数组编写一个类型,数组的元素只能是键的一部分?
type InputType = {
name: string;
phone: string;
num: number;
numRun: number;
numEdit: number;
posiRun: number;
posiEdit: number;
}
const preferArray = ['name', 'num', 'numRun']
const preferArray = ['name', 'num', 'numRun', 'abc'] // should complain the error because abc is not part of key from InputType
【问题讨论】:
标签: typescript typescript-typings typescript2.0