Here are the types that I have:
Foo {
foobar: any
}
Bar {
fooBarBar: any;
}
I want to use a function defined like this:
this.api.submit(param: Foo | Bar)
When trying to use it, I encountered an issue:
this.api.submit(param.foobar) // does not exist on Bar
Error: Property 'foobar' does not exist on type 'Foo| Bar'.
Property 'foobar' does not exist on type 'Bar '
I thought TypeScript would automatically determine which model to use based on the union, so why am I getting this error?
To get around this issue, I found that using bracket notation param['foobar'] resolves the error.