I believe that in the following example, the variable a should be compatible with the parameter arg, seeing as it is a compatible subset of the union.
type FooUnion = string | { id: string };
function foo (arg: FooUnion[]) {
console.log(arg);
}
const a: string[] = ['a'];
foo(a);
FooUnion (object type) This type is incompatible with const a: string[] = ['a'];
Problem due to variance. Use this instead:
type FooUnion = string | { id: string };
function foo (arg: $ReadOnlyArray<FooUnion>) {
console.log(arg);
}
const a: string[] = ['a'];
foo(a);
Most helpful comment
Problem due to variance. Use this instead: