2016-08-24 40 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

相關問題