Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda