typescript type of object code example
Example 1: typescript type object
type Dictionary = {
[key: string]: any
}
Example 2: typescript object type
let endedCoord: {x: number, y: number} = {
x: -1,
y: -1,
}
Example 3: typescript get type of object property
type Data = {
value: number;
text: string;
};
type textProperty = Data["text"];
const data = {
value: 123,
text: 'hello'
};
type textProperty = typeof data["text"];
Example 4: angular type of string
if(typeof myVariable === 'string'){
}
Example 5: typescript type of object values
const data = {
value: 123,
text: 'text'
};
type Data = typeof data;