Sure. A function's type consists of the types of its argument and its return type. Here we specify that the callback parameter's type must be "function that accepts a number and returns type any":

class Foo {
    save(callback: (n: number) => any) : void {
        callback(42);
    }
}
var foo = new Foo();

var strCallback = (result: string) : void => {
    alert(result);
}
var numCallback = (result: number) : void => {
    alert(result.toString());
}

foo.save(strCallback); // not OK
foo.save(numCallback); // OK

If you want, you can define a type alias to encapsulate this:

type NumberCallback = (n: number) => any;

class Foo {
    // Equivalent
    save(callback: NumberCallback) : void {
        callback(42);
    }
}
Answer from Ryan Cavanaugh on Stack Overflow
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ typescript-function-as-parameter-with-arguments
How to pass a Function as a Parameter in TypeScript | bobbyhadz
February 27, 2024 - The wrapper function calls the passed-in function with the numbers and returns the result. ... Copied!function wrapper( a: number, b: number, // ๐Ÿ‘‡๏ธ function parameter doMath: (a: number, b: number) => number, ) { return doMath(a, b); } The wrapper function expects a function parameter that takes 2 numbers as arguments and returns a number.
Discussions

How to pass function and arguments of that function as parameters in typescript - Stack Overflow
See similar questions with these tags. ... 2 Typescript - pass a function and its arguments to another function & enforce number and types of args ยท 0 Pass a function that uses other functions as parameter in Javascript More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to pass a value of type Parameters<T> to the function of type T
// <--- This fails to compile! Well, to start with, your if/else clause is the other way around More on reddit.com
๐ŸŒ r/typescript
13
19
March 20, 2022
typescript - Is it a bad practice to pass instance as function parameter? - Software Engineering Stack Exchange
So I am learning how to use the factory function in javascript/typescript. I created a to-do list project where I had to pass the instance as a parameter to the function. I wanted to ask is it a bad More on softwareengineering.stackexchange.com
๐ŸŒ softwareengineering.stackexchange.com
July 1, 2022
How to get return type of function passed in as a parameter
ReturnType, but you might need to change unknown to any or otherwise it will stay unknown. Edit: as of 4.6 instead of any you can also do this: ) => ReturnType> More on reddit.com
๐ŸŒ r/typescript
12
2
December 18, 2023
๐ŸŒ
LogRocket
blog.logrocket.com โ€บ home โ€บ how to pass a typescript function as a parameter
How to pass a TypeScript function as a parameter - LogRocket Blog
May 15, 2025 - Despite the difference in the number of parameters between the two functions, TypeScript allows this assignment due to duck typing. Itโ€™s a small note, but itโ€™s important to remember: the number of arguments isnโ€™t utilized in type definitions for functions in TypeScript. Now that we know precisely how to construct types for our functions, we need to ensure we type the functions that we pass ...
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ bytes โ€บ passing-functions-as-parameters-in-typescript
Passing Functions as Parameters in TypeScript
August 20, 2023 - In the above example, processGreeting() is a function that accepts a string and a function as parameters. The passed function fn takes in a string as a parameter and return a string. TypeScript provides a feature called "type aliasing" which allows you to create a new name for a type.
๐ŸŒ
TypeScript
typescriptlang.org โ€บ docs โ€บ handbook โ€บ 2 โ€บ functions.html
TypeScript: Documentation - More on Functions
Because both overloads have the same argument count and same return type, we can instead write a non-overloaded version of the function: ... This is much better! Callers can invoke this with either sort of value, and as an added bonus, we donโ€™t have to figure out a correct implementation signature. Always prefer parameters with union types instead of overloads when possible ยท TypeScript will infer what the this should be in a function via code flow analysis, for example in the following:
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ typescript โ€บ typescript_parameterized_function.htm
TypeScript - Parameterized a Function
The data type of the value passed must match the type of the parameter during its declaration. In case the data types dont match, the compiler throws an error. On compiling, it will generate following JavaScript code. //Generated by typescript 1.8.10 function test_param(n1, s1) { console.log(n1); console.log(s1); } test_param(123, "this is a string");
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/typescript โ€บ how to pass a value of type parameters to the function of type t
r/typescript on Reddit: How to pass a value of type Parameters<T> to the function of type T
March 20, 2022 -

So I'd like something like this:

myFunc(4, "foo", true) // some function that takes a particular set of args

const wrappedFunction = makeWrappedFunction(myFunc)

wrappedFunction(6, "bar", false)

I'd like the type of arg types and return type of wrappedFunction to match the original. I thought I could do:

type Func = (...args: any) => any

async function wrap<T extends Func> (
   fn: T, args?: Parameters<T>
): Promise<ReturnType<T>> {

   // do stuff

   if (!args)
     return await fn()
   else   
     return await fn(...args)    // <--- This fails to compile!
}

The error is that args is not iterable. Now I see that Parameters<T> returns a tuple. But how do I "repass" those args to fn?

Thanks geniuses!!

๐ŸŒ
Javatpoint
javatpoint.com โ€บ typescript-function-parameter
TypeScript Function Parameter - javatpoint
TypeScript Function Parameter with typescript tutorial, typescript introduction, versions, typescript and javascript, features, components, installation, typescript first program, typescript types, etc.
๐ŸŒ
Total TypeScript
totaltypescript.com โ€บ passing-types-to-functions
How To Pass Types To Functions | Total TypeScript
February 26, 2024 - Most functions in TypeScript can't receive types. A common example where you might want to pass a type is when calling document.getElementById. ... We know that audioElement is going to be a HTMLAudioElement. This type comes from the DOM typings, which we'll talk about later. So, it makes sense that we should be able to pass it to document.getElementById: ... Expected 0 type arguments, but got 1.2558Expected 0 type arguments, but got 1.
๐ŸŒ
Medium
fab1o.medium.com โ€บ named-parameters-in-typescript-288d90f35639
Named Parameters in TypeScript - Fabio Costa
January 30, 2024 - Creating an object to serve as a parameter for a function is called named parameters or named arguments. In general, parameter refers to the function parameter, and argument refers to the value passed in to the parameter.
๐ŸŒ
xjavascript
xjavascript.com โ€บ blog โ€บ typescript-passing-function-as-parameter
Mastering Function Passing in TypeScript โ€” xjavascript.com
For example, in the performOperation function, we used the MathOperation type to ensure that only functions that take two numbers and return a number are passed. Keep your functions and their types as simple and readable as possible. Use descriptive names for function types and parameters.
๐ŸŒ
Reddit
reddit.com โ€บ r/typescript โ€บ how to get return type of function passed in as a parameter
r/typescript on Reddit: How to get return type of function passed in as a parameter
December 18, 2023 -

I'm writing a debounce function that takes a function and returns a debounced version. I'd like to maintain the type safety of the original function in the debounced version so I need to infer the types of the parameters and return value of the original function. I'm struggling with the latter.

This is how I'm currently defining the function:

function debounce<T extends (...args: any[]) => unknown>(  
 func: T
)

I'm able to use Parameters<T> to infer the original function's parameter types and enforce those on the returned function.

return (...args: Parameters<T>) => { 
 <debounce stuff>
 return func(...args)
}

How do I get the return type of the original function and enforce that?

๐ŸŒ
Total TypeScript
totaltypescript.com โ€บ workshops โ€บ typescript-generics โ€บ passing-type-arguments โ€บ add-type-parameters-to-a-function โ€บ solution
Pass Type Arguments to a Function | Total TypeScript
June 7, 2023 - 2:31 You'll find this come up with a lot of different use cases that you might want to implement, but also in like the built-in types with Set and Map and all of these different things. They often require you to pass in a type argument, even if they don't say that they require you to in order to make them type save. ... 0:00 The solution here is to first of all, add a generic onto createSet. The error that we're getting here is "Expected type arguments, but got 1." This here is a type argument that's being passed to a function.
๐ŸŒ
Tutorial Teacher
tutorialsteacher.com โ€บ typescript โ€บ typescript-function
TypeScript Functions
This is unlike JavaScript, where it is acceptable to pass less arguments than what the function expects. The parameters that don't receive a value from the user are considered as undefined. TypeScript has an optional parameter functionality.
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ article โ€บ how-to-pass-functions-params-in-react-typescript
How to Pass Functions & Params in React + TypeScript
May 27, 2025 - People try to pass data through ... end up with spaghetti logic. You need to pass values to functions. You need to do it cleanly. And TypeScript needs to be happy. Thatโ€™s it. Letโ€™s walk through how to pass parameters in every common React situation. handleClick(5) runs right away as React renders ...
๐ŸŒ
TypeScript
typescriptlang.org โ€บ docs โ€บ handbook โ€บ 2 โ€บ generics.html
TypeScript: Documentation - Generics
By declaring a default for a generic type parameter, you make it optional to specify the corresponding type argument. For example, a function which creates a new HTMLElement. Calling the function with no arguments generates a HTMLDivElement; calling the function with an element as the first ...