Answer the question
In order to leave comments, you need to log in
How to convince the typescript that unknown is possible in ReturnType?
Hello.
Oil painting (and cheese):
function call<F extends () => unknown>(f: F): ReturnType<F> {
return f()
}
Answer the question
In order to leave comments, you need to log in
TypeScript has a number of problems with functional types in generics due to their variance
.
Here is how the result will be similar, but works without problems:
function call<R>(f: () => R): R {
return f()
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question