typescript return type of object code example
Example 1: typescript get type of object property
type Data = {
value: number;
text: string;
};
type textProperty = Data["text"]; //string
//OR
const data = {
value: 123,
text: 'hello'
};
type textProperty = typeof data["text"]; //string
Example 2: typescript type of object values
const data = {
value: 123,
text: 'text'
};
type Data = typeof data;