typescript typeof object code example
Example 1: node js check type of variable
if (typeof i != "number") {
console.log('This is not number');
}
Example 2: custom types in typescript
type Websites = 'www.google.com' | 'reddit.com';
let mySite: Websites = 'www.google.com'
let mySite: Website = 'www.yahoo.com'
type Details = { id: number, name: string, age: number };
let student: Details = { id: 803, name: 'Max', age: 13 };
let student: Details = { id: 803, name: 'Max', age: 13, address: 'Delhi' }
let student: Details = { id: 803, name: 'Max', age: '13' };
Example 3: typescript type of object values
const data = {
value: 123,
text: 'text'
};
type Data = typeof data;