Closed
Description
Bug Report
🔎 Search Terms
constructor, overload, TValue, jsdoc
🕗 Version & Regression Information
- This changed between versions "recent"? and ~1.77.1-ish
- I was unable to test this on prior versions because PR Improve
@overload
's interactions with constructors #52577 was not implemented (there was no reliable way to define overloads for class constructors)
Recent PR fixed the use of jsdoc-defined overloads for class constructors
- Bug report:
@overload
doesn't work for constructors #52477 - Bug fix (for jsdoc
@overload
): Improve@overload
's interactions with constructors #52577
That seems to have made it in to recent VS Code release; I'm using:
- Version: 1.77.1 (user setup)
- Commit: b7886d7461186a5eac768481578c1d7ca80e2d21
- Date: 2023-04-04T23:21:11.906Z
- Electron: 19.1.11
- Chromium: 102.0.5005.196
- Node.js: 16.14.2
- V8: 10.2.154.26-electron.0
- OS: Windows_NT x64 10.0.19045
- Sandboxed: Yes
⏯ Playground Link
(Updated to exhibit error): Playground link
💻 Code
// @ts-check
/**
* @template TValue
* @type {StringKeyMap<TValue>}
*/
export class StringKeyMap extends Map {
/**
* @constructor
* @overload
* @param {Iterable<[string, TValue]>} iterable
* @param {string} form
*//**
* @constructor
* @overload
* @param {string} form
*//**
* @constructor
* @overload
* @param {Iterable<[string, TValue]>} iterable
*//**
* @constructor
* @overload
*/
constructor(A, B) {
super()
// ...
}
/**
* @override
* @param {string} key
* @param {TValue} value
* @returns {this}
*/
set(key, value) {
// normalize key (removed for brevity)
return super.set(key, value)
}
}
/** @type {StringKeyMap<number>} */
const foo = new StringKeyMap() // <-- code hint error appears here
🙁 Actual behavior
In VS Code editor, if I try and instantiate my class using code like this:
class foo {
// ...
/** @type {StringKeyMap<string>} */
#tags
/**
* @param {Iterable<string>} tags
*/
constructor(tags) {
this.#tags = new StringKeyMap() // <-- error shows here
}
// ....
}
This happens:
Hovering the error shows:
The code still works fine when used in node, the issue is constrained to the VS Code editor which seems to think TValue
is a type rather than a template.
Possibly related to comment here about type checking being broken: #52477 (comment)
🙂 Expected behavior
TValue
is a template and thus should adopt the @type {StringKeyMap<string>}
defined for #tags
.