Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Generics; ReturnType<Function> not assignable to ReturnType<Function & (conditional type)> #31602

Copy link
Copy link
@AnyhowStep

Description

@AnyhowStep
Issue body actions

TypeScript Version: TS Playground version (3.4.1), 3.5.0-dev.20190523

Search Terms: ReturnType, function, conditional type

Code

declare function doThing<
    F extends () => any
>(
    f: () => ReturnType<F>
): void;

//== This fails ==
type Bar<F extends () => any> = (
    & (() => ReturnType<F>)
    //Should be the same as `unknown`
    & (F extends any ? unknown : unknown)
);

function bar<F extends () => any>(f: F) {
    /*
        Fail
        
        Type 'ReturnType<F>' is not assignable to type
        'ReturnType<(() => ReturnType<F>) & (F extends any ? unknown : unknown)>'
        
        Type '() => any' is not assignable to type
        'F extends any ? unknown : unknown'
    */
    doThing<Bar<F>>(() : ReturnType<F> => {
        return f();
    });

    //Fail
    //Type '() => any' is not assignable to type 'F extends any ? unknown : unknown'
    const t: (
        F extends any ? unknown : unknown
    ) = ((): any => 3);

    //OK!
    const t2: (
        unknown
    ) = ((): any => 3);
}

//== This works ==
type Bar2<F extends () => any> = (
    & (() => ReturnType<F>)
    & unknown
);

function bar2<F extends () => any>(f: F) {
    //OK!
    doThing<Bar2<F>>(() : ReturnType<F> => {
        return f();
    });
}

Expected behavior:

All failures should work.

Actual behavior:

They do not work.

Playground Link: Playground

Related Issues:

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.