Skip to content

QuizNot attempted

Overriding a native prop

A generic <Input<T>> wants its own value?: T. Why Omit the native value instead of just intersecting?
type InputProps<T> = Omit<ComponentProps<'input'>, 'value'> & { value?: T };
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • An intersection would combine both value types ((string | number | readonly string[]) & T) instead of replacing it
  • Intersecting two object types intersects the types of a property they share, so ComponentProps<'input'> & { value?: T } would demand a value that is both a native input value and a T (often never in practice)
  • Omit removes the native key first so yours replaces it.
  • Not 'faster at runtime': types are erased.
  • Not 'intersections can't contain optional properties': they can.
  • Not 'T inferred as any': inference is unaffected
  • the property type is the problem.