Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!