Skip to content

@overload doesn't check implementation against overload signatures #52367

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

#51234 introduced a new @overload tag, but it doesn't have the same type-checking rules as TypeScript's overloads.

Namely that we ensure that for each overload, the implementation signature is assignable to that overload, allowing the return type to be bidirectionally assignable.

If we want the same results in checkJs, then the following should error:

// @ts-check

/**
 * @overload
 * @param {number} x
 * @returns {number}
 */

/**
 * @param {string} x
 * @returns {string}
 */
function wut(x) {
    return String(x);
}

wut(123).toFixed(2);

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions