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

83
Views
Tipo personalizado mecanografiado

Si tengo una interfaz en mecanografiado así

 interface MyInterface { id: number; image: string; text: "one thing" | "another" | "anotherthing" | "anotherthing" }

¿Cómo puedo factorizar mi tipo de texto con las canalizaciones para poder usarlo varias veces como tipo en mi programa? Parece que debería ser simple, pero no estoy seguro de cuál es la sintaxis.

Para mayor claridad, me gustaría poder usarlo como

 factoredOutType = "one thing" | "another" | "anotherthing" | "anotherthing" interface MyInterface1 { id: number; image: string; text: factoredOutType } interface MyInterface2 { name: factoredOutType }

etc... Parece que no puedo encontrar la sintaxis de esta pregunta, por lo que se agradece la ayuda.

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

0

Creo que solo necesitas la palabra clave type :

 type factoredOutType = "one thing" | "another" | "anotherthing" | "anotherthing"

No está cerca de un compilador ahora, así que realmente no puedo verificarlo, pero creo que funciona

about 4 years ago · Juan Pablo Isaza Report

0

puede formatear tipos de literales de cadena utilizando el literal de plantilla si sus tipos están relacionados o son dinámicos. p.ej

 type stringTypes = `${'hello' | 'world'}_id`; const a: stringTypes = 'hello_id';
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!