microsoft / microsoft/TypeScript

JsDoc with overloads and different generics results in wrong dts output

Open
#59,980 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: JSDoc Help Wanted
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

🔎 Search Terms

javascript jsdoc dts overload

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about jsdoc
⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.2&filetype=js#code/PQKhFgCgAIWgBALgUwLYAcA2BDF0DeAzogE4CWAdgOYC+0AopmshYlLAgPYBuyJmnbABN2ceOmwlsqAo2as6yJqhZsYYkskQBXEhUIEAFAEpoAXgB80bpzJCao4FCigI6hCgw48+AEadOJmwKOjkVVlEuXn5BEXdxSWlZZVVFFIj4zR09A3wTcysbOwd1J0gXMEj4Hj4BYSqJKRl8Cm1UXz40+TUOeCzdfSNTS2tbe0dnSFcGxObggE8u8J6QMuQAD3ROEkRoADNtCgBjRDJOCmhzwyVu03woAEh+vWh8kfwSkqA

💻 Code
/**
 * @template {string} Element
 * @overload
 * @param {Element} element
 * @returns {() => void}
 */

/**
 * @template {boolean} Element
 * @overload
 * @param {Element} element
 * @returns {() => void}
 */

/**
 * @overload
 * @param {number} element
 * @returns {() => void}
 */

/**
 * @param {any} element
 */
export function on(element) {
	return () => {}
}

🙁 Actual behavior

The resulting dts of the given JSDoc looks like this:

export function on<Element extends string>(element: Element): () => void;
export function on<Element extends string>(element: Element): () => void;
export function on(element: number): () => void;

As you can see the generic does extends string both times, but it should be extends boolean the second time

🙂 Expected behavior
export function on<Element extends string>(element: Element): () => void;
export function on<Element extends boolean>(element: Element): () => void;
export function on(element: number): () => void;
Additional information about the issue

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground reproduction and inspect how the three JSDoc overloads are converted into the generated .d.ts output. Verify that each overload preserves its own generic constraint, especially the second overload's extends boolean, and confirm the output matches the expected declarations.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.