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

91
Views
"[key in Keys]" works but not with any other extra key?

Can someone explain me this ?

Typescript can detect clashes if same keys in an object. Then why extra keys are not allowed ?

Typescript Playground

type Keys = "1" | "2" | "3" | "4" | "5";

// Works
type Foo = {
    [key in Keys]: string;
  };

// Errors
type Bar = {    
    extraKey : string;
    [key in Keys]: string;
}
type Jar = {    
    [key in Keys]: string;
    extraKey : string;
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can't add fields in such way to mapped types, but you can use an intersection:

type Bar = {    
    extraKey : string;
} & {
    [key in Keys]: string;
}

Playground

about 4 years ago · Juan Pablo Isaza Report

0

Since extraKey also has string value, following should work

type Bar = {    
    [key in Keys | "extraKey"]: string;
}
about 4 years ago · Juan Pablo Isaza 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!