how object destructuring in typescript code example
Example 1: typescript object destructuring
// declare an interface or a type
interface Person {
name: string;
age: string;
}
// destructure name and age from `obj` variable.
const { name, age }: Person = obj;
Example 2: destruct type definition typescript
interface User {
name: string;
age: number;
}
const obj: any = { name: 'Johnny', age: 25 };
const { name, age }: User = obj;