8000 Awaited return type of generic parameter not assignable to itself · Issue #50251 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Awaited return type of generic parameter not assignable to itself #50251
@wbt

Description

@wbt

Bug Report

🔎 Search Terms

generic function parameter 2322 return type

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about functions and common bugs that aren't bugs
  • I was unable to test this on versions before 4.5 because the Awaited keyword didn't exist.

⏯ Playground Link

Playground link with relevant code

💻 Code

type FetcherFunction = (
    identifier: number
) => Promise<string>; //fixed 'string' not tied to parameter types is part of simplification for example
type demoFine1 = ReturnType<FetcherFunction>; // Promise<string>
type demoFine2 = Awaited<ReturnType<FetcherFunction>>; //string
async function getterDemo<
    F extends FetcherFunction = FetcherFunction
>(
    fetcherFn: F,
    identifier: number,
) : Promise<Awaited<ReturnType<F>>> {
    let demo3: F;
    let result = await fetcherFn(identifier); //result is a string
    return result; //ERROR TS2322: Type 'string' is not assignable to type 'Awaited<ReturnType<F>>'
    //In the motivating example, lots more is done with the result and the return type is a type derived from it,
    //but the simpler example seems like it shouldn't be throwing an error: whether Awaited<ReturnType<F> is a
    //simple string or something more complex, that is what the promise returned by this async function resolves to.
}

🙁 Actual behavior

Error as noted.

🙂 Expected behavior

No TS2322 error; the above code works fine. The awaited return type of fetcherFn should be assignable to the return (resolve) value, which is the awaited return type of that function type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0