Dev Helpers
← Back

Infer a constructor's argument types

Infer a constructor's argument types using TypeScript.

Open this example in the interactive library

Source code

interface Named {
  name: string;
}
console.log(
  (() => {
    class Item {
      constructor(public name: string) {}
    }
    const args: ConstructorParameters<typeof Item> = ["api"];
    return new Item(...args).name;
  })(),
);

Sample output

api