Skip to content

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

Closed
@ahejlsberg

Description

@ahejlsberg

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions