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

ReturnType<ReturnType<>> in type alias results in never #21997

Closed
ghost opened this issue Feb 16, 2018 · 2 comments
Closed

ReturnType<ReturnType<>> in type alias results in never #21997

ghost opened this issue Feb 16, 2018 · 2 comments
Labels
Fixed A PR has been merged for this issue

Comments

@ghost
Copy link

ghost commented Feb 16, 2018

TypeScript Version: 2.8.0-dev.20180216

Search Terms: ReturnType conditional type

Code

export {};
type ReturnType<T extends (...args: any[]) => any> = T extends (...args: any[]) => infer R ? R : any;
type ReturnTypeReturnType<T extends (...args: any[]) => (...args: any[]) => any> = ReturnType<ReturnType<T>>;
type Expected = ReturnType<ReturnType<() => () => "abcdef">>; // correctly `"abcdef"`
type Actual = ReturnTypeReturnType<() => () => "abcdef">; // `never`
const x: Actual = "abcdef"; // Error

Expected behavior:

Actual same as Expected.

Actual behavior:

Actual is never.

The issue may be fixed by changing the definition of ReturnType to be T extends (...args: any[]) => infer R ? R : never;. Based on the rules in #21496 the behavior with any may be by design, but the global ReturnType definition currently uses any, so maybe the fix should be in lib.d.ts.

@falsandtru
Copy link
Contributor

I think anyway ReturnTypeReturnType<() => () => "abcdef"> shouldn't reach any. So we don't have to fix the ReturnType definition.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Mar 9, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Mar 9, 2018

I can not reproduce this on latest.

@mhegazy mhegazy closed this as completed Mar 9, 2018
@mhegazy mhegazy added this to the TypeScript 2.8 milestone Mar 9, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants