1if (fooOrBar instanceof Foo){
2 // TypeScript now knows that `fooOrBar` is `Foo`
3}
1// simple type
2type Websites = 'www.google.com' | 'reddit.com';
3let mySite: Websites = 'www.google.com' //pass
4//or
5let mySite: Website = 'www.yahoo.com' //error
6// the above line will show error because Website type will only accept 2 strings either 'www.google.com' or 'reddit.com'.
7// another example.
8type Details = { id: number, name: string, age: number };
9let student: Details = { id: 803, name: 'Max', age: 13 }; // pass
10//or
11let student: Details = { id: 803, name: 'Max', age: 13, address: 'Delhi' } // error
12// the above line will show error because 'address' property is not assignable for Details type variables.
13//or
14let student: Details = { id: 803, name: 'Max', age: '13' }; // error
15// the above line will show error because string value can't be assign to the age value, only numbers.
16
17
18