Within my code, there exists a class:
class Person {
name: string;
age: number;
gender: string;
constructor(params: any){
this.name = params.name;
this.age = params.age;
this.gender = params.gender;
}
}
My question is how can I extract a type from the class Person
that mirrors the following structure:
type PersonType = {
name: string;
age: number;
gender: string;
}
I want to avoid redundancy when defining the type by manually writing it out. Is there a way to automatically generate the type based on the class definition?
I wish to avoid duplicating the following code snippet:
name: string;
age: number;
gender: string;