Skip to content

3.9 regression: varargs in declaration files for JavaScript files break declaration syntax #38242

Closed
@TimvdLippe

Description

@TimvdLippe

TypeScript Version: 3.9.1-rc

Search Terms: jsdoc, varargs, declaration

Code

vararg.js:

/**
 * @param {!Object<string, function(string, ...*):*>} formatter
 * @param {string} format
 * @param {...*} var_args
 */
function takesVarargs(formatter, format, ...var_args) {
  formatter['pattern'](format, var_args);
}

tsconfig.json:

{
  "compilerOptions": {
    "module": "esnext",
    "target": "esnext",
    "outDir": "lib",
    "declaration": true,
    "allowJs": true,
    "checkJs": true
  },
  "files": [
    "vararg.js"
  ]
}

Expected behavior:
(Run with TypeScript 3.8.3)

/**
 * @param {!Object<string, function(string, ...*):*>} formatter
 * @param {string} format
 * @param {...*} var_args
 */
declare function takesVarargs(formatter: {
    [x: string]: (arg0: string, ...arg1: any[]) => any;
}, format: string, ...var_args: any[]): void;

Actual behavior:
(Run with TypeScript 3.9.1-rc)

/**
 * @param {!Object<string, function(string, ...*):*>} formatter
 * @param {string} format
 * @param {...*} var_args
 */
declare function takesVarargs(formatter: {
    [x: string]: (arg0: string, arg1: ...*) => any;
}, format: string, ...var_args: ...*): void;

Note that the function arguments varargs are not properly changed to ...arg1: any[] anymore and are now only arg1: ...*. This means that a subsequent composite usage of this declaration file will crash, as the syntax is not valid.

Playground Link: n/a as Playground doesn't allow me to show the declaration files if the language=JavaScript. Instead it shows me // Using JavaScript, no compilation needed.

Related Issues: A wild guess that #37757 might be related?

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesDomain: JavaScriptThe issue relates to JavaScript specificallyFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions