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

242
Views
En Typescript, ¿cómo paso un genérico a un tipo de acceso indexado?

Estoy refactorizando una tienda redux y quería crear un tipo de "Fábrica" que pudiera usarse para reducir el código duplicado.

Actualmente lo tengo como:

 interface CommonFactory<T, S> { Payload: Partial<S>; Action: Action<T> & { payload: this['Payload'] }; ActionCreator: ActionCreator<this['Payload']>; }

lo que me permite extraer un montón de tipos comunes simplemente escribiendo

 interface AppState { key1: any; key2: any; key3: any; } type Factory = CommonFactory<AppTypes, AppState>; type AppPayload = Factory['Payload']; type AppAction = Factory['Action']; type AppActionCreator = Factory['ActionCreator'];

Sin embargo, me he dado cuenta de que un Parcial para la carga útil no es correcto. Prefiero usar un Pick para que ActionCreator pueda especificar las propiedades que se devolverán. Esto tendría que ser aprobado no por Factory , sino por ActionCreator . Algo como

 const someActionCreator: AppActionCreator<'key1'> = (someData: any) => { return { type: SOME_ACTION_TYPE, payload: { key1: someData } } }

Pero no estoy seguro de cómo pasar un genérico a un tipo de acceso indexado.

about 4 years ago · Juan Pablo Isaza
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!