How should I structure my constructor if it will be invoked with the following code:
const user = new User({
username,
email
})
Both `username` and `email` are of type string.
Update:
Here is how you can implement this in TypeScript:
interface UserData {
username: string;
email: string;
}
class User {
username: string;
email: string;
constructor({ username, email }: UserData) {
this.username = username;
this.email = email;
}
}
const user = new User({
username: "exampleuser",
email: "user@example.com"
});
console.log(user);