Question:
Usually I use Typescript’sParameters
to receive all parameters required by a function of a class:get(id: number)
.I’m currently trying to get parameters of function that has the following signature:
Parameters
it supposes that the T
is never
and I can’t pass my own T
into the parameters of such arrow function to get something like Parameters<Controller["get"]<T>>
to get proper generic when I call my function like in the beginning.Edit 1: Minimal Reproducible Example


Answer:
TypeScript 4.7 introduced instantiation expressions as implemented in microsoft/TypeScript#47606, so if you have a valuef
of a generic function type, you can specify the type parameters of that function without calling it. Let’s say your function declaration isT
and U
with, say, number
and string
, to get a new expression:typeof
type operator to get the type of such a expression without actually creating one:f
, or a property of a variable. If you only have the type of f
, then you can’t instantiate its type parametersTest
, you do have a value of the generic function type you care about. It’s this.genericFunction
or this.genericFunctionPromise
:this
in TypeScript 4.7. Ugh. This turns out to be a bug in TypeScript, see microsoft/TypeScript#49451. This bug has been fixed at microsoft/TypeScript#49521, so typescript@next
nightly build will work, and it will be released with TypeScript 4.8.If you need to get this working in TS4.7, you could declare a fake variable of type
Test
and use it instead, since we just care about types:If you have better answer, please add a comment about this, thank you!