Skip to content

jsdoc: Optional function parameters don't have optional type within function definition #61579

@rschristian

Description

@rschristian

🔎 Search Terms

jsdoc optional parameters

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about jsdoc. It seems the intention is to support this behavior, per the handbook -- jsdoc supported types listing it as an example.

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.2.2&ssl=10&ssc=2&pln=1&pc=1&filetype=js#code/PQKhCgAIUgBAHAhgJ0QW0gbwM4BdkCWAdgOYC+kk8AjJALSQCCkehpVK6AdFDApxhz5iJALwV4AJnpMikAPbxcBeUUQAbDqgwAKAOLz5JdQFNIAYXXzsAV2RnsATyK5EADwCUvOEm1ZWIhQA2vAAzAC6MoxE8rgAFibICkoqapq+6JA6AFIAygAi8gDGLM6unjzQPgL+wqTB8AAsogBEuCZ4LZEM0cnKqhpamQDuBPGQiJAAJiYAZog26riQAG4aNibesPa4dkTYtWzkkAAqcQQHF5DxZva2S7zA4LM2REX9cgGk2Ll1JL9HbA6GgAGiokjBYUhjQ8WCglCooXAZCAA

💻 Code

/**
 * @param {string}  p1 - A string param.
 * @param {string=} p2 - An optional param (Google Closure syntax)
 * @param {string} [p3] - Another optional param (JSDoc syntax).
 * @param {string} [p4="test"] - An optional param with a default value
 * @returns {string} This is the result
 */
function stringsStringStrings(p1, p2, p3, p4) {
    p3
}

🙁 Actual behavior

Within the definition of stringsStringsStrings(), p3 has an incorrect type of string.

🙂 Expected behavior

The parameter is optional, the type should be string | undefined.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions