Skip to content
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

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

Closed
HerringtonDarkholme opened this issue Sep 30, 2016 · 3 comments
Closed
Labels
Suggestion An idea for TypeScript Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it

Comments

@HerringtonDarkholme
Copy link
Contributor

HerringtonDarkholme commented Sep 30, 2016

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.

@dead-claudia
Copy link

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

@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Dec 13, 2016
@RyanCavanaugh RyanCavanaugh added Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it and removed In Discussion Not yet reached consensus labels Jan 24, 2017
@RyanCavanaugh
Copy link
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.

@HerringtonDarkholme
Copy link
Contributor Author

Thanks for your explanation!

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Suggestion An idea for TypeScript Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it
Projects
None yet
Development

No branches or pull requests

4 participants