I'm trying to evaluate an object based on two types, without looking explicitly at its children, as a value could not exist (based on my use-case).
Let's say I have two interfaces with different properties.
interface A
& interface B
How would I check an object is Type of A or Type of B?
I've tried the following:
interface A {
foo: "value";
}
interface B {
bar: "value";
}
const object = {
bar: "value"
};
function isA(object: any): object is A {
if (object as A) {
return true;
} else {
return false;
}
}
console.log(isA(object));
However, the result is always returned as True
.
Codesandbox https://codesandbox.io/s/elastic-gagarin-01c7y?file=/src/index.ts:0-243