Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
Autocompletion not working when Intersecting with Generic Param

I have the following code (playground here)

import React from 'react';

const colors = { a: 1, b: 1, } as const

type Props<P extends Record<string, any> = {}, T extends HTMLElement = HTMLDivElement> = { customProp: keyof typeof colors | `${string}px` } & React.HTMLAttributes<T>
    & P // <---------- try to comment this part and notice autocompletion for MyBox

type BoxReturn = <P extends Record<string, any> = {}, T extends HTMLElement = HTMLDivElement>(
    props: Props<P, T>
) => JSX.Element

const Box = React.forwardRef(function Box(
    props,
    ref
) { return null }) as BoxReturn

const MyBox = () => <Box customProp="ab" /> // no auto complete, but it _is_ type safe 

const MyBox2 = () => <Box<{}> customProp="a" /> // this works, notice the generic

const MyBox3 = (params: Props<{ foo: string }>) => <Box {...params} foo="bar" /> // why is `foo="bar"` allowed when i didnt do <Box<{foo: string} />

The Autocompletion(ctrl + space) doesn't work with VScode for MyBox while it does for MyBox2. If you comment & P then Autocompletion will work for MyBox as well.

Questions

  • When doing just <Box /> the default value for P should be {} so why do i have to specify it in MyBox2?
  • If i do const MyBox3 = (params: Props<{ foo: string }>) => <Box {...params} foo="bar" /> why does the generic param's type become {foo: string}?
  • For MyBox why is customProp's type never?

Thank you so much 🙏

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda