Skip to content

Handle TypeScript optional property syntax #76

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Daniel-Knights
Copy link
Contributor

This PR adds support for TypeScript optional property syntax by removing ? characters after keys in object types.

@Daniel-Knights Daniel-Knights force-pushed the handle-typescript-optional-properties-syntax branch from b235e9a to 5b4e889 Compare May 2, 2025 13:55

```js
/**
* @type {{a: number, b: string}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try if @type {{a: number, b: string=}} would work in JSDoc? It would be nice if we could keep the information that b is meant to be optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS doesn't allow this syntax

Screenshot 2025-05-25 at 11 43 17

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the translation to JSDoc, not the input type annotation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@type {{a: number, b: string=}} ends up as Object in the generated docs.

You'd have to define it as:

/**
 * @type {object}
 * @property {number} a
 * @property {string=} b
 */

To output docs for each property and whether or not they're optional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants