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

173
Views
objeto de uso mecanografiado como la definición de tipo

digamos que tengo

 clients/ index.ts client1.ts client2.ts myApp.ts // client1.ts export default class Client1 {} // client2.ts export default class Client2 {} // clients/index.ts import Client1 from './client1'; import Client2 from './client2'; export { client1, client2 };

Ahora, quiero usar todos los clientes en myApp y configurar el tipo para que se base en esto, es decir

 // myApp.ts import * as clients from './clients'; type Clients = { [key in keyof typeof clients]: clients[key]; } const allClients: Clients = { client1: new clients.Client1(), client2: new clients.Client2(), }

El código anterior no es válido, clients[key]; arroja un error sobre Cannot use namespace 'clients' as a type. pero básicamente quiero poder importar todos los clientes y usar ese objeto como definición de tipo para todos mis clientes. es posible?

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

0

¿Por qué no simplemente crear la interfaz manualmente? No creo que puedas crearlo sobre la marcha de esa manera. Y probablemente quiera que sus tipos sean estáticos en tiempo de ejecución de todos modos. Será mucho más fácil razonar sobre ellos.

Simplemente defina una interfaz con los clientes enumerados en myApp o donde los exporte.

 import * as clients from './clients'; interface Clients = { client1: clients.client1, client2: clients.client2, } const allClients: Clients = { client1: new clients.Client1(), client2: new clients.Client2(), }
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!