I'm trying to understand the use case where typescript allows instances to pass union type type-checking when it doesn't pass any individual component. The example I'm looking at is using types
type Bar = {
bar: true
bar2: number
}
type Baz = {
baz: number
}
type Foo = Bar | Baz
which catches
const bazArg: Baz = {baz: 5, bar: true}
as a type error, but does not catch
const bazArg: Foo = {baz: 5, bar: true}
This allows bugs like
const fn = (foo: Foo): number => 'bar' in foo ? foo.bar2 : foo.baz
const bazArg: Foo = {baz: 5, bar: true}
console.log(fn(bazArg)) // logs undefined