TypeScript常见问题汇总

理解 type Record<K extends keyof any, T> = { [P in K]: T; }

// type KEY = keyof any //即 string | number | symbol
type Record<K extends keyof any, T> = {
    // [P in K]的意思是对象的key可以取 string,number,symbol.
    [P in K]: T;
};
// 规定对象类型 key 为 string, value 为 boolean
type Classes = Record<string, boolean>
posted @ 2022-05-06 11:29  __Bowen  阅读(39)  评论(0编辑  收藏  举报