If to pass a variable which is a function, and also the type of that function need to be a generic one, it’s useful to define a generic function type when using typescript.

For example, in order to to pass value to the callback, how to define GenericFunctionType?

interface Foo<T> {
  foo(value: T, callback: GenericFunctionType<T, unknown>): void
type GenericFunctionType<TInput, TReturn> = {
  (args: TInput): TReturn
type GenericFunctionType<TInput, TReturn> = (args: TInput) => TReturn
interface GenericFunctionType<TInput, TReturn> {
  (args: TInput): TReturn

Finally, to finish the example interface Foo by implementing it:

class Coo<T> implements Foo<T> {
  foo(value: T, callback: GenericFunctionType<T, unknown>) {

const sf = new Coo<string>()
sf.foo('Hello world', (v) => console.log(v))
const nf = new Coo<number>()
nf.foo(123, (v) => console.log(v))
const bf = new Coo<boolean>()
bf.foo(true, (v) => console.log(v))


[LOG]: "Hello world"
[LOG]: 123
[LOG]: true