Since I've updated from Typescript version 4.0 to 4.4 I get some errors with Generics and I am not able to fix them.
const isFirstData = <TFirst, TSecond>(
item: { type: ItemType.FIRST; data: TFirst } | { type: ItemType.SECOND; data: TSecond }
): item is { type: ItemType.FIRST; data: TFirst } => item.type === ItemType.FIRST;
const rows: ({
type: ItemType.SECOND;
data: TSecond;
} | {
type: ItemType.FIRST;
data: TFirst;
})[];
const item = rows[0];
const height = isFirstData(item) ? First?.value : Second?.value;
// Argument of type '{ type: ItemType.SECOND; data: TData; } | { type: ItemType.FIRST; data: TFirst; }' is not assignable to parameter of type '{ type: ItemType.FIRST; data: TData; } | { type: ItemType.SECOND; data: TData; }'.
Can somebody explain what has changed in typescript and how to fix my error?