2017-10-07 9 views

Répondre

1

Vous pouvez y parvenir en utilisant intersection types:

type PotatoAll = { [all: string]: string }; 
type Potato = PotatoAll & { a: number }; 

let p = {} as Potato; 

p['foo'] = 'foo'; 
p.a = 1; 
p['a'] = 1; 

p['foo'] = 1; //error 
p['a'] = 'a'; //error 
p.a = 'a'; //error