Reputation: 38109
I have a 3rd party lib that returns a BaseClass.
I then want to add a properties to BaseClass and use it. But I get a compile error.
var mySubclass : Subclass = MethodThatReturnsBaseClass();
Compile Error:Type Baseclass is not assignable to type Subclass
interface Subclass extends BaseClass {
title: string;
}
How should this be written?
Upvotes: 0
Views: 54
Reputation: 276255
How should this be written?
interface Subclass extends BaseClass {
title?: string;
}
var mySubclass : Subclass = <Subclass>MethodThatReturnsBaseClass();
I prefer method 1 as it is more semantically correct
Upvotes: 1