If I have a TypeScript interface like below:
interface myInterface {
prop1: string;
prop2: string;
prop3: number;
prop4: boolean;
..
..
..
prop30: string
}
I want to create a Class that implements myInterface and I only know the verbose way to do so like below:
class MyClass implements myInterface {
prop1;
prop2;
prop3;
prop4;
..
..
prop30;
constructor(data: myInterface) {
this.prop1 = data.prop1;
this.prop2 = data.prop2;
this.prop3 = data.prop3;
this.prop4 = data.prop4;
..
..
this.prop30 = data.prop30;
}
}
Is there any way I can make this syntax shorter or any better way to implement such Class from interface?
var x: myInterface = { prop1: "hello", prop2: "world", prop3: 77, ...}is a valid instance of the interface. You don't need a class here (just in case you weren't aware).