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

Consider removing special checks for specialized signatures with other overloads #6143

Closed
DanielRosenwasser opened this issue Dec 18, 2015 · 2 comments
Labels
Breaking Change Would introduce errors in existing code Committed The team has roadmapped this issue Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@DanielRosenwasser
Copy link
Member

Specialized signatures needing to be compatible with an overload was an artificial requirement due to issues in #943. Now that we've fixed that, we should consider what we're going to do with this rule.

Could we remove it wholesale? That would potentially be a breaking change, but it seems like good one. Basically, the situations you'd run into this would be where you have something like the following...

function doThing(x: "dog"): Dog;
function doThing(x: "cat"): Cat;
function doThing(x: string): Animal;
function doThing(x: string, y?: string): Moose {
}

Where now we'd check if the implementation was assignable to the specialized signatures and give an error. That seems like a good change.

@DanielRosenwasser DanielRosenwasser added Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. In Discussion Not yet reached consensus labels Dec 18, 2015
@weswigham
Copy link
Member

Given that we know recognize string types wholesale across the typesystem, would it be possible to just remove the concept of 'specialized signatures' entirely (since most of the logic should be handled by normal overload resolution)? I'd love to see Signature.hasStringLiterals go away.

@DanielRosenwasser
Copy link
Member Author

The problem is that specialized signatures are bubbled up to the top of the signature list because of the rule I want to get rid of here. Here's a basic example:

interface I {
    m(x: "ugh"): boolean;
}

interface I {
    m(x: "hello"): string;
    m(x: "world"): number;
    m(x: string): any;
}

With this ordering of interfaces, the signatures will be ordered as

m(x: "hello"): string;
m(x: "world"): number;
m(x: string): any;
m(x: "ugh"): boolean;

Without bubbling specialized signatures at the top during overload resolution, a call to m with "ugh" will never return type boolean. You'll always get any.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript and removed In Discussion Not yet reached consensus labels Jan 4, 2016
@DanielRosenwasser DanielRosenwasser added the Breaking Change Would introduce errors in existing code label Jan 8, 2016
@DanielRosenwasser DanielRosenwasser added Fixed A PR has been merged for this issue Committed The team has roadmapped this issue Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined and removed Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Feb 10, 2016
@mhegazy mhegazy closed this as completed Feb 11, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone Feb 11, 2016
@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
Breaking Change Would introduce errors in existing code Committed The team has roadmapped this issue Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants