cjmling / findings

Notes on stuff i finds worth keeping for quick reference later on.
2 stars 0 forks source link

Typescript define dynamic key object type #303

Open cjmling opened 2 years ago

cjmling commented 2 years ago

Use Record

For example

const periods : Record<string, string> = {}; 

can be for

periods['a'] = 'aaaaa';
periods['b'] = 'cccccc';
const periods : Record<string, string[]> = {}; 

can be for

periods['a'] = ['aaaaa', 'bbbb'];
periods['b'] = ['cccccc' , 'dddd'];

Typescript define dynamic key object type