Skip to content

Overloads Are Not Generated as Expected When Using @Overload Tag to Declare Overloads of Functions Assigned to a Prototype #53181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
philippfromme opened this issue Mar 9, 2023 · 0 comments · Fixed by #53317
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@philippfromme
Copy link

philippfromme commented Mar 9, 2023

Bug Report

When using the @overload tag to declare overloads of functions assigned to a prototype (e.g. Foo.prototype.bar) the overloads are not generated as expected. However, for functions that are not assigned to a prototype it works.

🔎 Search Terms

overload

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about overload

⏯ Playground Link

Playground link with relevant code

💻 Code

Type declarations are generated for the following code:

export function Foo() {}

/**
 * @overload
 * @param {string} a
 *
 * @return {void}
 */

/**
 * @overload
 * @param {number} a
 * @param {string} b
 *
 * @return {void}
 */

/**
 * @param {string|number} a
 * @param {string} [b]
 *
 * @return {void}
 */
Foo.prototype.bar = function(a, b) {}

🙁 Actual behavior

export function Foo(): void;
export class Foo {
    /**
     * @overload
     * @param {string} a
     *
     * @return {void}
     */
    /**
     * @overload
     * @param {number} a
     * @param {string} b
     *
     * @return {void}
     */
    /**
     * @param {string|number} a
     * @param {string} [b]
     *
     * @return {void}
     */
    bar(a: string | number, b?: string): void;
}

🙂 Expected behavior

export function Foo(): void;
export class Foo {
    /**
     * @overload
     * @param {string} a
     *
     * @return {void}
     */
    /**
     * @overload
     * @param {number} a
     * @param {string} b
     *
     * @return {void}
     */
    /**
     * @param {string|number} a
     * @param {string} [b]
     *
     * @return {void}
     */
    bar(a: string): void;

    bar(a: number, b?: string): void;
}

Compare this to generating type declarations for the following code:

/**
 * @overload
 * @param {string} a
 *
 * @return {void}
 */

/**
 * @overload
 * @param {number} a
 * @param {string} b
 *
 * @return {void}
 */

/**
 * @param {string|number} a
 * @param {string} [b]
 *
 * @return {void}
 */
export function bar(a, b) {}

Result:

export function bar(a: string): void;
export function bar(a: number, b: string): void;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
2 participants