Skip to content

Bad JSDoc comments leads to generate invalid declaration file #37703

Description

TypeScript Version: 3.9.0-dev.20200328

Search Terms: JSDoc A required parameter cannot follow an optional parameter.

Code

/**
 * @param {string} password Passphrase
 * @param {string} [targetRoomId] Room ID to target a specific room.
 * Restores all rooms if omitted.
 * @param {object} opts Optional params such as callbacks
 */
function x(password, targetRoomId, opts) {}
x()

Expected behavior:
Generate declaration file:

function x(password: string, targetRoomId?: string, opts?: object): void

Actual behavior:
Generate declaration file:

function x(password: string, targetRoomId?: string, opts: object): void
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ Notice the question mark `?` has gone
// error TS1016: A required parameter cannot follow an optional parameter.

Playground Link: https://www.typescriptlang.org/v2/en/play?ts=3.9.0-dev.20200328&useJavaScript=true#code/PQKhFgCgAIWgBADgQwE7ILbQN4GcAuqAlgHYDmAvtCrrgO4D2qAJtAArK2IAW6uAplFgIU6LHkKlK0ANr40ZfvgBKDBhgCSzALrRV66BoAi0fA1MKl0ZNFyJ+AYyIAzIg+io1GAHRC4y-gImQOsAG1CPL1xoF2h1Inx8fmZfGDgkNEwcBgAjACtHfCoGRHxogHlSogYSZAjRTGjcAFcHbmtohzrQnOQHAGtcP2AoZ2aSB3xqkmgADwAKGnomZgAaC1RFFS8tdZKygEocCigoBYOoIA

Hover the mouse on the function x, you can see it's signature is inferred as function x(password: string, targetRoomId?: string, opts: object): void which is wrong.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions