Skip to content

Declaration emit breaks with varargs and this type specified in function type parameter #38550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TimvdLippe opened this issue May 13, 2020 · 1 comment · Fixed by #39814
Closed
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@TimvdLippe
Copy link
Contributor

TypeScript Version: 4.0.0-dev.20200512

Search Terms: jsdoc, declaration, varargs

Code

clazz.js:

export class Clazz {
  /**
   * @param {function(this:Object, ...*):*} functionDeclaration
   */
  method(functionDeclaration) {}
}

tsconfig.json:

{
  "compilerOptions": {
    "outDir": "lib",
    "declaration": true,
    "allowJs": true,
    "checkJs": true
  },
  "files": [
    "clazz.js"
  ]
}

Expected behavior:
The emitted declaration file is:

export class Clazz {
    /**
     * @param {function(this:Object, ...*):*} functionDeclaration
     */
    method(functionDeclaration: (...args: any[]) => any): void;
}

Actual behavior:

export class Clazz {
    /**
     * @param {function(this:Object, ...*):*} functionDeclaration
     */
    method(functionDeclaration: (args: any, ...args: any[]) => any): void;
}

Subsequent usages of a composite project break, as args is duplicated in the method argument types.

Note that removal of this:Object fixes the issue. Also, the following properly emits:

export class Clazz {
  /**
   * @param {function(this:Object, ...*):T} functionDeclaration
   * @template T
   */
  method(functionDeclaration) {}
}

Note here that the T is unused in the function, but it fixes the emitted declaration file.

Playground Link:

Related Issues: #38242 (we are successfully able to compile DevTools with the above workaround and the fix for #38242)

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 14, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone May 14, 2020
@sandersn
Copy link
Member

The code that emits named, non-new parameters in closure function types is just wrong as far as I can tell.

sandersn added a commit that referenced this issue Jul 29, 2020
Previously, parameters with names that were not `new` were treated like
rest parameters. This is incorrect: parameters with the name `this`
should emit a `this` parameter.

Fixes #38550
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jul 29, 2020
@sandersn sandersn added Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Jul 29, 2020
sandersn added a commit that referenced this issue Jul 29, 2020
* Fix this parameter emit for JSDocFunction types

Previously, parameters with names that were not `new` were treated like
rest parameters. This is incorrect: parameters with the name `this`
should emit a `this` parameter.

Fixes #38550

* ❤️ quote style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants