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

179
Vistas
Typescript interface with unknown number of generic properties which all should be typed as booleans

I want to make a typescript interface with unknown number of generic properties which all should be typed as booleans. If I wanted to make an interface with property 'foo' and a generic value I would do:

export interface Foo<T> {
  foo: T;
}

Since I want to do basically the opposite I tried

export interface booleansMap<T> {
  T: boolean;
}

but I got

'T' is defined but never used.(@typescript-eslint/no-unused-vars)

from eslint

Having trouble finding this in the docs (probably not googling with the correct nomenclature) - so I was wondering if anyone understands and can explain how to make such an interface

It should be able to handle something like:

{
  foo: false,
  bar: true,
  baz: false
}

or

{
  foo: true,
}

or any other object with any number of properties as long as all of the values will be booleans...

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You don't need generics for this. You can just use [K: string] to specify a general key:

type booleanMap = { [K: string]: boolean }

with interface definition:

interface booleansMap {
  [K: string]: boolean;
}

Or alternatively use Record:

type booleanMap = Record<string, boolean>

Playground

over 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