I'm not sure if my question is clear, so I'll try to elaborate.
Say I have a class MyClass that implements an interface MyInterface. Apart from the properties required by the implementation (in this case, myProp1), it has an additional property myProp2 as shown in the snippet below:
interface MyInterface {
myProp1: string;
}
class MyClass implements MyInterface {
myProp2 = '2';
constructor(public myProp1: string) {}
}
Then, upon creating an instance of the class, I assigned it the MyInterface type. TypeScript doesn't complain even though instance has properties not specified in MyInterface:
let instance: MyInterface = new MyClass('1'); // no type error
But when attempting to access the added property (myProp2), I get an error:
console.log(instance.myProp2); // 'myProp2' does not exist on type 'MyInterface'. Did you mean 'myProp1'?
Is this a bug, or is it the intended behavior here?