Skip to content

[Suggestion] should Overloads not differ only by return type? #11281

Closed

Description

I wonder if this is a bug. But at least this is a discrepancy between specification and implementation.

It appears in TS 1.03 function overloading cannot differ only by return type, but in TS1.1 this restriction was lifted.

function a(): number
function a(): string
function a(): any { return null as any}

SO question: http://stackoverflow.com/questions/25022331/overloads-cannot-differ-only-by-return-type

Source: https://github.com/Microsoft/TypeScript/blob/release-1.0.3/src/compiler/resources/diagnosticMessages.json#L1024

Spec: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#1212-ambient-function-declarations

This should also impact call signatures in intersection types.

Activity

  1. dead-claudia commented on Dec 13, 2016

    @dead-claudia

    TS is at 2.1 now...I'd advise checking it out. It's got some pretty cool features. 😉

  2. added
    Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix it
    and removed on Jan 24, 2017
  3. RyanCavanaugh commented on Jan 24, 2017

    @RyanCavanaugh
    Member

    Three options on the table:

    • Correctly detect all unreachable signatures
    • Detect some unreachable signatures but not others
    • You're on your own, good luck

    The first option is expensive (O(n^2) and we have large n in many places) and for the sake of checking code that is very rarely wrong. The second option is hard to explain, still expensive, and ends up confusing people because sometimes they get an error and sometimes they don't. The third is undesirable for obvious reasons, but is at least "free" in certain sense of the word and can be mostly covered with TSLint rules in places where there's some danger of getting it wrong.

  4. HerringtonDarkholme commented on Jan 24, 2017

    @HerringtonDarkholme
    ContributorAuthor

    Thanks for your explanation!

  5. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SuggestionAn idea for TypeScriptWon't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix it

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions