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

114
Vistas
Cree automáticamente un tipo booleano desde cualquier interfaz en mecanografiado

Tengo esta interfaz de ejemplo:

 interface Input { api_method: string; ip: string; utc_millis: number; user_agent: string; rr_sets: { name: string; rr_type: string; ttl: number; value: string; }[]; }

y desea crear automáticamente esta interfaz a partir de ella:

 interface Output { api_method: boolean; ip: boolean; utc_millis: boolean; user_agent: boolean; rr_sets: { name: boolean; rr_type: boolean; ttl: boolean; value: boolean; }[]; }

De la documentación Aquí descubrí que esto:

 type Output= { [Key in keyof Input]: boolean; };

creará este tipo:

 type Output = { api_method: boolean; ip: boolean; utc_millis: boolean; user_agent: boolean; rr_sets: boolean; }

¿Cómo se haría eso con cualquier tipo/interfaz anidado?

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

0

Puede usar un condicional en su tipo asignado:

 interface Input { api_method: string; ip: string; utc_millis: number; user_agent: string; rr_sets: { name: string; rr_type: string; ttl: number; value: string; }[]; } type AllBoolean<T> = { [K in keyof T]: T[K] extends Array<infer U> ? AllBoolean<U>[] : boolean } type Output = AllBoolean<Input> const output_test: Output = { api_method: true, ip: true, utc_millis: false, user_agent: true, rr_sets: [{ name: true, rr_type: true, ttl: false, value: true, }] }
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