2016-08-24 1 views

Répondre

1

Vous devez utiliser un Indexable Types:

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

Puis:

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

(code in playground)