typescript object type key-value code example
Example 1: typescript keyof
interface Person {
name: string;
age: number;
location: string;
}
type K1 = keyof Person;
type K2 = keyof Person[];
type K3 = keyof { [x: string]: Person };
Example 2: typescriprt specify type of key
var stuff: { [key: string]: string; } = {};
stuff['a'] = '';
stuff['a'] = 4;
interface StringMap { [key: string]: string; }
var stuff2: StringMap = { };
Example 3: typescript type of object values
const data = {
value: 123,
text: 'text'
};
type Data = typeof data;