Generic functions that have an @overload in their JSDoc produce TS2304: Cannot find name 'T' errors.
In const assignments this applies only to the base params (the params in all the overloads are fine). In function definitions this applies to all params except those of the first overload.
CHANGES.md does not address this new "feature".
Steps to reproduce
const createElementC = /**
* @template {keyof HTMLElementTagNameMap} T
* @param {T}t
* @param {NodeList|HTMLCollection=}c
*
* @overload
* @param {T}t
* @return {HTMLElementTagNameMap[T]}
*
* @overload
* @param {T}t
* @param {NodeList|HTMLCollection}c
* @return {HTMLElementTagNameMap[T]}
*/(t, c) => {
/* ... omitted for brevity ... */ return document.createElement(t)
}
/**
* @template {keyof HTMLElementTagNameMap} T
* @param {T}t
* @param {NodeList|HTMLCollection=}c
*
* @overload
* @param {T}t
* @return {HTMLElementTagNameMap[T]}
*
* @overload
* @param {T}t
* @param {NodeList|HTMLCollection}c
* @return {HTMLElementTagNameMap[T]}
*/
function createElementF(t, c) {
/* ... omitted for brevity ... */ return document.createElement(t)
}
The real use case is, of course, far more complex than the repro above.
Behavior with typescript@6.0
tsc --checkJs --strict --noEmit index.js
No output, no errors.
Behavior with tsgo
tsgo --checkJs --strict --noEmit index.js
index.js:5:13 - error TS2304: Cannot find name 'T'.
5 * @param {T}t
~
index.js:22:12 - error TS2304: Cannot find name 'T'.
22 * @param {T}t
~
index.js:30:12 - error TS2304: Cannot find name 'T'.
30 * @param {T}t
~
index.js:32:35 - error TS2304: Cannot find name 'T'.
32 * @return {HTMLElementTagNameMap[T]}
~
index.js:32:35 - error TS2538: Type 'T' cannot be used as an index type.
32 * @return {HTMLElementTagNameMap[T]}
~
Found 5 errors in the same file, starting at: index.js:5
Generic functions that have an
@overloadin their JSDoc produceTS2304: Cannot find name 'T'errors.In
constassignments this applies only to the base params (the params in all the overloads are fine). Infunctiondefinitions this applies to all params except those of the first overload.CHANGES.md does not address this new "feature".
Steps to reproduce
The real use case is, of course, far more complex than the repro above.
Behavior with
typescript@6.0No output, no errors.
Behavior with
tsgo