2016-08-24 75 views

回答

1

您应该使用Indexable Types

interface IThings { 
    [name: string]: string; 
} 

然后:

let a = {} as IThings; 
a["x1"] = "y"; // ok 
a["x2"] = 4; // Type 'number' is not assignable to type 'string' 

code in playground

相关问题