Dev Helpers
← Back

Infer a function's output

Infer a function's output using TypeScript.

Open this example in the interactive library

Source code

type ElementOf<T> = T extends readonly (infer U)[] ? U : never;
console.log(
  (() => {
    type Output<T> = T extends (...args: never[]) => infer R ? R : never;
    const v: Output<() => number> = 9;
    return v;
  })(),
);

Sample output

9