Skip to content

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

Closed
@ghost

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions