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

218
Vistas
Typescript - How to get the type of an optional nested prop in an interface

The code below throws me the ts error: Property 'id' does not exist on type '{ id: string } | undefined'. because group is optional. In spite of that I want to get the type of id. How can i do that?

interface list{
  group?: {
    id: string; 
  }
}

const something: list["group"]["id"] = {} as any;

TS Playground

(Ignore the {} as any, this is just an example)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Typescript provides the Partial and Required helpers to make all properties of an object either optional or non optional.

You can read more about typescript utility types here.

So in your case you can use Required<list> to turn group into a non optional property:

interface list{
  group?: {
    id: string; 
  }
}

const something: Required<list>["group"]["id"] = "foo"

Typescript Playground

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