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

159
Views
Typescript JSX con genéricos: el parámetro tiene implícitamente un tipo 'cualquiera'

Cuando se usa la sintaxis JSX con Generics, Typescript puede inferir propiedades normalmente, excepto el tipo de parámetros de función.

Código de ejemplo:

 interface Dictionary { a: JSX.IntrinsicElements['a']; button: JSX.IntrinsicElements['button']; } type Props<T extends 'a' | 'button'> = Dictionary[T] & { as: T; }; function Test<T extends 'a' | 'button'>(args: Props<T>) { return null; } <Test as="a" href="#" onClick={(arg) => {}} />; // Parameter 'arg' implicitly has an 'any' type. Test({ as: 'a', href: '#', onClick: (arg) => {}, // No error });

Parque infantil TS

Si coloco el mouse sobre la propiedad onClick, puede indicar el tipo de onClick (React.MouseEventHandler<HTMLAnchorElement>), pero aún no puede inferir el tipo del parámetro.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simplemente defínalo explícitamente como any con args: any y debería dejar de mostrarlo como error :)

about 4 years ago · Juan Pablo Isaza Report
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!