Typescript相关
axlroseart opened this issue · comments
axlroseart commented
1
axlroseart commented
通过key值动态引用对象属性会报错:
element implicitly has an 'any' type because expression of type 'string' can't be used to index type
解决方案:
const getKeyValue = <T extends object, U extends keyof T>(obj: T) => (key: U) => obj[key];
axlroseart commented
字典对象属性引用:
interface GenericDict<T> {
[key: string]: T;
}
let dictionary: GenericDict<string[]> = {};
dictionary["example"] = ["foo"];
// Works fine!
方便点:
let dict:{[key:string]:string[]} = {};