Closed
Description
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.