-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
Milestone
Description
Bug Report
🔎 Search Terms
"jsdoc overload"
"constructor overload jsdoc"
"overload jsdoc example"
🕗 Version & Regression Information
I've only just tried using this feature. Specifically based on the recent merged PR #51234 which is intended to fix #25590
- I was unable to test this on prior versions because JSDoc overload tag #51234 was not merged.
⏯ Playground Link
Playground link with relevant code
💻 Code
//@ts-check
/*
I want following overloads for contructor
(a and b are differnt types):
new Foo()
new Foo(a)
new Foo(b)
new Foo(a,b)
I want to define overloads using JSDoc, ideally,
but would settle with a d.ts file. I can't find
any coherent examples other than the one in merged
PR, which does not seem to work for constructors.
*/
class Foo {
#a
#b
/**
* @overload
* @constructor
* @param {string} a
* @param {number} b
*//*
* @overload
* @constructor
* @param {number} a
*//*
* @overload
* @constructor
* @param {string} a
*//*
* @constructor
*/
constructor(a, b) {
this.#a = a
this.#b = b
}
}
var a = new Foo()
var b = new Foo('str')
var c = new Foo(2)
var d = new Foo('str', 2)
🙁 Actual behavior
Code hints are not indicating the presence of overloads, and type checking does not seem to be applied correctly based on parameter combination.
🙂 Expected behavior
While instantiating the class I would expect to see the "up/down" arrows in the code hint that indicates presence of overloads (and allows cycling through the hints for the various overloads). I would also expect type checking to be applied properly.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.