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<Foo> != ReturnType<typeof foo> #24277

Copy link
Copy link
@AnyhowStep

Description

@AnyhowStep
Issue body actions

TypeScript Version: Version 2.9.0-dev.20180516

Search Terms: generic function returntype

I couldn't think of a good title for this,

Code

type Delegate<T> = () => T;

function executeGeneric<
    X,
    DelegateT extends Delegate<X> 
>(delegate: DelegateT): ReturnType<DelegateT> {
    //Type 'X' is not assignable to type 'ReturnType<DelegateT>'.
    const x: ReturnType<typeof delegate> = delegate();
    //Type 'X' is not assignable to type 'ReturnType<DelegateT>'.
    const y: ReturnType<DelegateT> = delegate();
    //Type 'X' is not assignable to type 'ReturnType<DelegateT>'.
    return delegate();
}

Expected behavior:

Return successfully.

Intuitively, to me,

  1. delegate is of typeDelegateT.
  2. ReturnType<DelegateT> and ReturnType<typeof delegate> should be the same

However,

Actual behavior:

Type 'X' is not assignable to type 'ReturnType<DelegateT>'.

Playground Link: Here

Related Issues:

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript

    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.