Thanks to the comments above, especially the one from @jcalz, I've simplified my code by removing Omit<T, K>
in favor of just T
. This gets rid of the error while keeping the same intent.
export type AugmentedRequired<T extends object, K extends keyof T = keyof T> = T &
Required<Pick<T, K>>;
type Cat = { name?: boolean };
type Dog = { name?: boolean };
type Animal = Cat | Dog;
type NamedAnimal<T extends Animal = Animal> = AugmentedRequired<T, 'name'>;
export function isNamedAnimal<T extends Animal = Animal>(animal: T): animal is NamedAnimal<T> {
// Error is on NamedAnimal<T> in this line
return 'name' in animal;
}