You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interface IFoo {
foo: string;
}
interface IBar {
bar: string;
}
class Foo implements IFoo{
foo: string;
}
class Bar implements IBar{
bar: string;
newProperty: string;
}
let x:Foo|Bar = new Bar();
let y:IFoo = x as IFoo; // Works as expected, no errors
let u:Foo|Bar = new Bar();
let z:IBar = u as IBar; //Does not work IFF Bar contains more properties than IBar
We have a situation where a property is a union of several classes, and we would like to cast it to the correct interface in different situations. However this does not seem to work if the class has properties that is not present on the implemented interface. Playground link