Skip to content

Suggestion: support function overloading in type annotation comments #21921

Closed
@douglas-treadwell

Description

@douglas-treadwell

I'm adding type annotations to a JS codebase, and one problematic case I've come across is that I cannot overload function signatures using comment-based annotations.

/** @type {(flag: true) => integer;} */
/** @type {(flag: false) => string;} */
function getResult(asInteger) {
   // do stuff here
}

The workaround for now would be splitting the function into two functions, or type-casting at each use of the function. So far my choice will be to split the function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions