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

135
Vistas
TypeScript: how to make a property conditional from an existing type?

So let's say I have

type Link = {
  text: string;
  link: string;
}

interface BigLink extends Link {
  some: number;
  something: string;
  else: string;
}

but I have a variable that shares all these properties except that the link property can be optional. I don't want to create a whole new type just to change one field to link?: string. Is there a way to do something like

type OptionalBigLink = BigLink & { link?: string }

so that I can overwrite the link field and make it optional. ^ The above code still throws an error when I don't pass in the link property.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Yes you can.

type OptionalBigLink = Partial<Pick<BigLink, "link">> & Omit<BigLink, "link">;

Some tests in the playground

about 4 years ago · Santiago Trujillo Denunciar

0

You can use Omit to remove the property from BigLink and then do the intersection.

type OptionalBigLink = Omit<BigLink, "link"> & { link?: string }
about 4 years ago · Santiago Trujillo Denunciar
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