I am learning TypeScript and I do not understand things about interface.
interface IMyClass extends MyClass {
color: number;
IsResizable: boolean;
title: string;
}
class MyClass {
added: string;
//color: number;
//IsResizable: boolean;
//title: string;
constructor(element: HTMLElement) {
}
test() {
var that: IMyClass = <IMyClass>this; // Error
}
}
I got this error:
Severity Code Description Project File Line Suppression State
Error TS2352 Neither type 'this' nor type 'IMyClass' is assignable to the other.
Type 'MyClass' is not assignable to type 'IMyClass'.
Property 'color' is missing in type 'MyClass'. TypeScrip app.ts 17 Active
The error disappear if I uncomment attributes. So my question is : do I have to duplicate interface attributes into my class ? What if I have a huge interface? Any other solution?