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

Merge same function signatures for intersection types #31930

Open
saschanaz opened this issue Jun 16, 2019 · 2 comments
Open

Merge same function signatures for intersection types #31930

saschanaz opened this issue Jun 16, 2019 · 2 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@saschanaz
Copy link
Contributor

TypeScript Version: 3.6.0-dev.20190611

Search Terms: function signature merge

Code

interface X { 
    name: string;
    method(): void;
}

interface Y { 
    index: number;
    method(): void;
}

var z: X & Y;

z.method(); // <--- Put your cursor here

Expected behavior: IntelliSense should ideally show only one signature.

Actual behavior: It shows two exactly same signatures. Not harming, but weird.

Playground Link: https://www.typescriptlang.org/play/#src=interface%20X%20%7B%20%0D%0A%20%20%20%20name%3A%20string%3B%0D%0A%20%20%20%20method()%3A%20void%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20Y%20%7B%20%0D%0A%20%20%20%20index%3A%20number%3B%0D%0A%20%20%20%20method()%3A%20void%3B%0D%0A%7D%0D%0A%0D%0Avar%20z%3A%20X%20%26%20Y%3B%0D%0A%0D%0Az.method()

@jcalz
Copy link
Contributor

jcalz commented Jun 16, 2019

This is equivalent to asking for repeated overload signatures to be collapsed. Which seems plausible for adjacent overloads and less plausible when distinct signatures appear between them.

@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Jun 25, 2019
@millsp
Copy link
Contributor

millsp commented Jun 25, 2019

@saschanaz I created ts-toolbelt for this purpose

import {O} from 'ts-toolbelt'

interface X { 
    name: string;
    method(): void;
}

interface Y { 
    index: number;
    method(): void;
}

type Z = O.Merge<X, Y>
var z: Z

The last in wins (and, it is compatible with overloads). We should not alter the behavior of &, in my opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants