Result of F#foo()
is not assignable to ReturnType<F["foo"]>
#47900
Labels
Duplicate
An existing issue was already created
Bug Report
🔎 Search Terms
extends interface union ReturnType, not assignable to ReturnType
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
I'm unable to write a type annotation for
function run()
that allows the return type to be refined based on the specificF
being passed in (with the requirementF extends Foo
). When I add theReturnType
annotation, the function body has an error. When I remove it, the function return type is inferred based on the interface requirement of"bar" | "baz"
rather than the more specific return type ofF["foo"]
.Writing
return f.foo() as ReturnType<F['foo']>
also works, but theas
cast is undesirable.🙂 Expected behavior
It should be possible to write a type annotation for
run
such thatrun({ foo: () => "bar" as const })
is inferred to return"bar"
.The text was updated successfully, but these errors were encountered: