Dev Helpers
← Back

Infer the first argument

Infer the first argument using TypeScript.

Open this example in the interactive library

Source code

type ElementOf<T> = T extends readonly (infer U)[] ? U : never;
console.log(
  (() => {
    type First<T> = T extends (arg: infer A) => unknown ? A : never;
    const value: First<(s: string) => void> = "ok";
    return value;
  })(),
);

Sample output

ok