Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
Define type to array behavior

I need to crate a type that can hold an array where each element is a function that gets the previous output as an input. For example, a valid array is:

const pipe: SpecialArray = [
    () => string,
    (prev:string) => number,
    (prev:number) => boolean
];

An invalid array would be:

const pipe: SpecialArray = [
    () => string,
    (prev:number) => number, // <-- Here number should be string
    (prev:number) => boolean
];

Is there a way to define such structure in TypeScript?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I believe no, since Array is homogenous, you'll have to define in the form [(a: string) => number, (b: number) => boolean], and you can't really enumerate all (unless a code generator is used).

about 4 years ago · Juan Pablo Isaza Denunciar

0

It is impossible in TypeScript to create standalone type for such kind of array. In order to do that you should create compose function, infer each function from arguments and validate it. Please see my article and questions/answers on SO: first , second, third.

Also you can check this compose function in fnts lib

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda