axlroseart / drx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typescript相关

axlroseart opened this issue · comments

通过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];

字典对象属性引用:

interface GenericDict<T> {
       [key: string]: T;
}

let dictionary: GenericDict<string[]> = {};
dictionary["example"] = ["foo"];
// Works fine!

方便点:
let dict:{[key:string]:string[]} = {};