Closed
Description
TypeScript Version: 2.1.1 / nightly (2.2.0-dev.20170228)
Went to StackOverflow with this first and the consensus there seems to be that this is a bug.
Here's my question again for convenience:
Consider a situation where an object can have exactly the FooBar
or Baz
interface listed below.
interface FooBar {
foo: string;
bar: string;
}
interface Baz {
baz: string;
}
It's my understanding that this "one or the other" situation can be handled by creating a union between FooBar
and Baz
.
type FooBarOrBaz = FooBar | Baz;
So far so good...
The issue I'm having is that the following object passes type checking:
const x: FooBarOrBaz = {
foo: 'foo',
baz: 'foo',
};
Expected behavior: x
should not pass type checking. It's neither FooBar
nor Baz
, but rather a combination between the two.
Actual behavior: x
passes type checking.