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

No variadic tuple inference from trailing optional to non-optional #39607

Closed
ahejlsberg opened this issue Jul 14, 2020 · 1 comment · Fixed by #39614
Closed

No variadic tuple inference from trailing optional to non-optional #39607

ahejlsberg opened this issue Jul 14, 2020 · 1 comment · Fixed by #39614
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@ahejlsberg
Copy link
Member

TypeScript Version: 4.0.0-dev

Code

declare function getUser(id: string, options?: { x?: string }): string;

declare function getOrgUser(id: string, orgId: number, options?: { y?: number, z?: boolean }): void;

function callApi<T extends unknown[] = [], U = void>(method: (...args: [...T, object]) => U) {
    return (...args: [...T]) => method(...args, {});
}

callApi(getUser);  // Error, but shouldn't be
callApi(getOrgUser);  // Error, but shouldn't be

Expected behavior:

No errors.

Actual behavior:

Errors.

Playground Link:

https://www.typescriptlang.org/play/index.html?ts=4.0.0-dev.20200714&ssl=10&ssc=49&pln=1&pc=1#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwHMQMBVAZxBgAotgAueMjGLVAgGnhwAds8yA-AwDe8AB5DGzVgXgBfAJQMmLNgG4AUBtCRYCFOj74iGAPIwC5SjXpTVHLhYCSt1MgC2AI0qceRwSLwAJ6Sbl4+8ABekp44OBAgUPiKDABuOLSaGgaYuPhgUBAQAILcWAA8ACrwIGIYIKjAZPBoANaoOADuqADaALrwALzw-ZwkQ-DptAB8VO7EABY4tlQAdOuwBGQMPeurlb6eAFbgGH0KQ9PwJBfCGvAP8HAYyDD4axsW2yN7leeX8HmGCWwA+q02ZE4wkUmjkWgKRVKWCoJisMAUageAHosfAAKIwGA4GCcTzIDCMJbICDAVAAcgp3g0CJKZRRxHMlgo6Mx8Bx+MJxNJ5MpOGptIZ8CZQA

Related Issues:

#39595

@ahejlsberg ahejlsberg self-assigned this Jul 14, 2020
@ahejlsberg ahejlsberg added this to the TypeScript 4.0.1 milestone Jul 14, 2020
@ahejlsberg ahejlsberg changed the title Permit variadic tuple inference from trailing optional to non-optional No variadic tuple inference from trailing optional to non-optional Jul 14, 2020
@ahejlsberg
Copy link
Member Author

In #39281 we switched to making no inferences from or to trailing optional elements in variadic tuples. That's a bit too strict. It is in fact fine to make inferences from trailing optional elements as long as they're made to non-optional elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants