After using TypeScript for 1 year, I've noticed that creating objects to pass can be a bit cumbersome and manual.
In TypeScript, interfaces are used for type definitions and store all the necessary parameters. Is there a way to automatically generate an object from an interface?
For example:
export interface User {
name: string;
email: string;
}
I wish the following code could be automated, as currently I have to create a class with a constructor instead of directly using the interface.
user {
name: ''/null/undefined,
email: ''/null/undefined
}
let user: User = new User() // this will show error
However, I can easily create a new object using the following class.
export class User {
constructor() {
name: string;
email: string;
}
}
new User();
So, what do you think is better - creating a constructor class or using an interface?