typescript type object with any key code example
Example 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
Example 2: typescript type of object values
const data = {
value: 123,
text: 'text'
};
type Data = typeof data;