Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

JSDoc optional property in object #39906

Copy link
Copy link
@mastermatt

Description

@mastermatt
Issue body actions

TypeScript Version: 3.9.x & 4.1.x

Search Terms: jsdoc optional

There seems to be a regression since version 3.9.x where optional params in JSDocs are not converted correctly in declaration files. Several issues were created (linked below) and patches were made, however, it seems that params nested inside objects are still not correctly handled as optional when surrounded by brackets.

Code

/**
 * Does Foo
 *
 * @param {object} opts
 * @param {string} [opts.bar] - is optional
 * @returns void
 */
function foo(opts ) {
  // ..
}

Expected behavior: (as well as actual behavior <=3.8.3)

declare function foo(opts: {
    bar?: string;
}): void;

Actual behavior:

declare function foo(opts: {
    bar: string;
}): void;

Related Issues:
#39111 was addressed with #39487, but it doesn't seem that nested properties were covered in that fix.
#39123 and #39457 seem to relate to Closure notation, not sure if they're related.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: JSDocRelates to JSDoc parsing and type generationRelates to JSDoc parsing and type generation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.