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 #39111

Copy link
Copy link
@lieser

Description

@lieser
Issue body actions

The JSDoc optional property syntax described on https://jsdoc.app/tags-property.html behaves unexpectedly.

TypeScript Version: 3.9.5, Version 4.0.0-dev.20200615

Search Terms: jsdoc, optional

Code

/**
 * User type definition
 * @typedef {Object} User
 * @property {string} email
 * @property {string} [nickName]
 */

/** @type {User} */
const user = {email: ""}; // as expected email is required, but nickName is not
const nickName = user.nickName; // expected type string|undefined, but type is string

// expected error TS2532: Object is possibly 'undefined'.
console.log(nickName.length)

Expected behavior:

nickName has type string|undefined, and the console.log line should be an error with strict enabled

Actual behavior:

nickName has type string, no error reported even with strict enabled.

Playground Link:

Related Issues:

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.

Type

No type
No fields configured for issues without a type.

Projects

No projects

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.