Skip to content
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

Support type parameter defaults in JSDoc template tags #45481

Closed
5 tasks done
rbuckton opened this issue Aug 17, 2021 · 0 comments · Fixed by #45483
Closed
5 tasks done

Support type parameter defaults in JSDoc template tags #45481

rbuckton opened this issue Aug 17, 2021 · 0 comments · Fixed by #45483
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript

Comments

@rbuckton
Copy link
Member

Suggestion

Add support for type parameter defaults in JSDoc @template tags, to match parity with type parameter defaults in TypeScript:

// ts
type Foo<T = number> = T

// js
/**
 * @template [T=number]
 * @typedef {T} Foo
 */

🔍 Search Terms

jsdoc template type parameter default

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Implement type parameter defaults in @template similar to optional parameters in @param:

/**
 * @param {string} [x=1]  - NOTE: TS parses the expression `1` but ignores it.
 */
function f(x) {}

/**
 * @template {string} [T="hello"]
 * @typedef {T} Foo
 */
  • Brackets around T would be required (so as not to misinterpret existing documentation comments
  • A bracketed template type must have a default (unlike @param which allows [name] on its own).

📃 Motivating Example

Improves JavaScript JSDoc type annotation parity with TypeScript type annotations.

💻 Use Cases

Used for JavaScript development using the TypeScript language service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants