Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
Not understanding issue with typescript subtype constraint instantiation

Here is a link to a Typescript Playground that shows the issue.

import { ChangeEvent } from "react"
import { Control, useController } from "react-hook-form"

export interface RequiredEditorProps<Value> {
  onChange: (event?: ChangeEvent | Value) => void
  onBlur: () => void
  name: string
  value: Value
}

type Props<Value, EditorProps extends RequiredEditorProps<Value>> = Omit<
  EditorProps,
  "onChange" | "onBlur" | "name" | "value"
> & {
  Editor: (props: EditorProps) => JSX.Element
  control: Control
  fieldName: string
  initialValue: Value
}

export const RHFAdapter = <Value extends any, EditorProps extends RequiredEditorProps<Value>>({
  Editor,
  control,
  fieldName,
  initialValue,
  ...editorProps
}: Props<Value, EditorProps>) => {
  const {
    field: { onChange, onBlur, name, value },
    // fieldState: { invalid, isTouched, isDirty },
    // formState: { touchedFields, dirtyFields }
  } = useController({
    name: fieldName,
    control,
    defaultValue: initialValue,
  })

  return <Editor onChange={onChange} onBlur={onBlur} name={name} value={value} {...editorProps} />
}

Basically it complains about the render of Editor because the spread props might be a different subtype of the RequiredEditorProps constraint. This is definitely a part of TS that I find it difficult to grasp. It would seem to me that any additional properties of EditorProps would be spread into ...editorProps and then into the render so I don't really understand what the issue is.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!