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

489
Views
Texto mecanografiado: generar tipos a partir de un objeto

Acabo de empezar a aprender Typescript y necesito ayuda con este ejemplo.

 const alphabet = { 'a': {lower: 97, upper: 65}, 'b': {lower: 98, upper: 66} } type Char = 'a' | 'b' function printSome(char: Char){ console.log(alphabet[char]) }

En lugar de actualizar manualmente el tipo Char , me gustaría actualizar dinámicamente los tipos generados desde el objeto del alphabet .

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Podrías usar los operadoreskeyof y typeof :

 const alphabet = { 'a': {lower: 97, upper: 65}, 'b': {lower: 98, upper: 66} } type Char = keyof typeof alphabet; function printSome(char: Char){ console.log(alphabet[char]) }

Básicamente, esto convierte el alphabet en un tipo y luego obtiene las claves de ese tipo.

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!