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

312
Views
TypeScript: ajuste los parámetros de la función en Promise<T>

Intento crear un tipo que tome un tipo de función, envuelva los parámetros de la función en Promise<> y devuelva un nuevo tipo: la misma función pero con parámetros como Promise, por ejemplo:

 type PromisedFn = PromisedArgs<(a: number, b: string | number) => void> // should produce (a: Promise<number>, b: Promise<string | number>) => void

Después de horas de devanarme los sesos, solo logré lograr ese código:

 type Func = (id: number, guid: number | string) => number | string; type FuncParams = Parameters<Func>; // FuncParams = [id: string, guid: string | number] type FuncWrappedParams = { [K in keyof FuncParams as Extract<K, '0'|'1'>]: Promise<FuncParams[K]> } // { 0: Promise<number>, 1: Promise<string | number> }

Todavía el objeto indexado por números no se puede aplicar como una matriz correctamente:

 type FuncWrappedParamsArray = [...args: FuncWrappedParams[]]; type WrappedParamsFunc = (...args: FuncWrappedParamsArray) => ReturnType<Func>; let func: WrappedParamsFunc = ( id: Promise<number>, guid: Promise<number | string> ) => 'TestString'; // ERROR: // Type '(id: Promise<number>, guid: Promise<number | string>) => string' // is not assignable to type 'WrappedParamsFunc'. // Types of parameters 'id' and 'args' are incompatible. // Type 'FuncWrappedParams' is missing the following properties from type 'Promise<number>': // then, catch, [Symbol.toStringTag]

No tengo idea de cómo manejar esto.

El problema #1 es como el anterior.

Problema n.º 2: la desventaja es que debemos conocer una serie de parámetros de función con anticipación: [K in keyof FuncParams as Extract<K, '0'|'1'>] .

over 4 years ago · Santiago Trujillo
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!