Overriding default jsdoc -> .d.ts conversion to get rid of ...args: any[]

193 views Asked by At

When using tsc to generate declarations only, JSDoc tags are used to infer types etc.

Is it possible to override the types inferred from the JSDoc?

Specifically, for a function using arguments, tsc will always add an ...args: any[] vararg parameter to the function declaration. I want to override that to get rid of it since arguments is only used for legacy reasons and there should be no vararg arguments to the function.

Example:

/**
 * @param {number} x
 */
function myLegacyFunction(x) {
  if (arguments.length > 1) {
    throw new Error();
  }
  return 42;
}

... will render

export function myLegacyFunction(x: number, ...args: any[]): number;

Note that even if I do use @param to document x and leave out args, it's still added implicitly. I also tried explicitly listing args as type ...never, but that also didn't help:

/**
 * @param {number} x
 * @param {...never} args
 */
function myLegacyFunction(x) {
  if (arguments.length > 1) {
    throw new Error();
  }
  return 42;
}

How can I make tsc understand that this function should simply be:

export function myLegacyFunction(x: number): number;

(Using typescript 4.2.3.)

0

There are 0 answers