79187037

Date: 2024-11-14 00:23:55
Score: 1.5
Natty:
Report link

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;
}
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @jcalz
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Julia McNeill