Answers for "typescriprt specify type of key"

1

typescriprt specify type of key

var stuff: { [key: string]: string; } = {};
stuff['a'] = ''; // ok
stuff['a'] = 4;  // error

// ... or, if you're using this a lot and don't want to type so much ...
interface StringMap { [key: string]: string; }
var stuff2: StringMap = { };
// same as above
Posted by: Guest on December-09-2020

Code answers related to "typescriprt specify type of key"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language