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

241
Views
Tipo de texto mecanografiado: Objeto con claves estáticas/fijas y claves dinámicas

¿Cómo creo un tipo de mecanografiado para un objeto, donde puedo tener un conjunto fijo y un conjunto dinámico de claves? Por ejemplo:

 export type APIOMethods = 'getA' | 'getB' | 'getC'; export type item = { divId: string; role: string; [key: K in APIMethods]?: any; }; // Not working ↑↑↑ 🔴 export type item = { divId: string; role: string; [key: APIMethods]: any; }; // Not working ↑↑↑ 🔴 // the object could look like this: {divId: '', role: '', getA: {}} OR {divId: '', role: '', getB: {}} OR {divId: '', role: '', getC: {}}
  • Texto mecanografiado Playground Enlace aquí
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Solución: usando un tipo de objeto mapeado :

 export type item = { [key in APIMethods]?: any; } & { divId: string; role: string; };

Después de jugar con el código más dentro de Visual Studio Code , el editor terminó sugiriendo usar un tipo de objeto asignado cuando había escrito esto antes

 export type item = { divId: string; role: string; [key: APIMethods]: any; ^🔴 An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.ts(1337) };
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!