How to get Argument Types from Function in TypeScript ? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In TypeScript, the Parameters utility type allows you to extract the types of a function's parameters. This is particularly useful when you want to work with the types of arguments dynamically, enabling functions that operate on any function's parameter types. In this article, we are going to see how to get argument types from functions in Typescript. Syntax:function exampleFunction(arg1: string, arg2: number, arg3: boolean): void { // Function body}// Use the Parameters utility type to get the argument typestype ArgumentTypes = Parameters<typeof exampleFunction>;function logArgumentTypes(...args: ArgumentTypes): void { args.forEach(arg => console.log(typeof arg));}ApproachStart by defining the function from which you want to extract the argument types.Utilize the Parameters utility type to extract the argument types.Design a function to log the types of arguments.Apply the extracted types in your logging function.Example: In this example, the logArgumentTypes function uses the typeof operator to log the type of each argument. JavaScript // Define a sample function function exampleFunction(arg1: string, arg2: number, arg3: boolean): void { // Function body } type ArgumentTypes = Parameters<typeof exampleFunction>; function logArgumentTypes(...args: ArgumentTypes): void { // Log the type of each argument args.forEach(arg => console.log(typeof arg)); } const args: ArgumentTypes = ['Geeks', 22, true]; logArgumentTypes(...args); Output: stringnumberbooleanExample 2: In this example, the printNumberTypes function now correctly logs the type of each number using the typeof operator. JavaScript function addNumbers(a: number, b: number): number { return a + b; } type AddNumbersArgs = Parameters<typeof addNumbers>; function printNumberTypes(...numbers: AddNumbersArgs): void { numbers.forEach(num => console.log(typeof num)); } const result: AddNumbersArgs = [10, 20]; printNumberTypes(...result); Output: numbernumber Comment More infoAdvertise with us Next Article How to get Argument Types from Function in TypeScript ? A amanv09 Follow Improve Article Tags : JavaScript Web Technologies TypeScript Similar Reads How To Get Types From Arrays in TypeScript? In TypeScript, arrays are a common data structure, but sometimes it's necessary to extract the types of elements stored in an array for type-checking or validation purposes. TypeScript provides several ways to extract types from arrays, enabling more type-safe operations.We will explore different me 3 min read How to Create a Generic Type Alias for a Generic Function in TypeScript ? In TypeScript, it is possible to create a generic type alias for a generic function. A generic type alias provides a descriptive name for a function with generic parameters, making it easier to understand the code. It also makes the code reusable and readable especially when you are dealing with com 2 min read How to create conditional types in TypeScript ? Conditional types in TypeScript enable defining types based on conditions, similar to conditional statements in code. They determine different types of values, making functions adaptable to various input types, and enhancing code flexibility and maintainability. Syntax: We can create conditional typ 3 min read How to Specify Return Type in TypeScript Arrow Functions ? To Specify the return type in the TypeScript arrow function, we have multiple approaches. In this article, we are going to learn how to Specify the type in the TypeScript arrow function. Below are the approaches used to Specify the return type in the TypeScript arrow function: Table of Content Expli 2 min read How to call Typescript function from JavaScript ? In this article, we will try to understand all the facts which are associated with how we may call typescript function from JavaScript. TypeScript supports the existing JavaScript function syntax for declaring and calling it within the program or the code snippet. Let us quickly understand how we ma 2 min read How to Create TypeScript Generic Function with Safe Type Matching ? In TypeScript, generic functions offer a powerful tool for creating flexible and reusable code that can work with various data types. However, ensuring type safety is crucial to prevent runtime errors and maintain code reliability. These are the following approaches:Table of ContentUsing Type constr 4 min read How to write a function in Typescript ? Writing a function in TypeScript is similar to writing it in JavaScript but with added parameters and return type. Note that any JavaScript function is a perfectly valid TypeScript function. However, we can do better by adding type.Syntax: Let's see a basic TypeScript function syntax (with two argum 4 min read How to Define a Generic Type for an Array in TypeScript ? Generics in TypeScript are a way to write reusable code that can work with different types of data. When it comes to defining generic types for arrays. TypeScript provides flexible options to ensure type safety while allowing for flexibility in the types of elements stored in the array.Table of Cont 3 min read How to get Function Parameters from Keys in an Array of Objects Using TypeScript ? In TypeScript, we can extract the function parameters from keys in an array of objects by going through object properties dynamically. We can use Generics and Type Assertion to get Function Parameters from Keys in an Array of Objects Using TypeScript. Below are the possible approaches: Table of Cont 3 min read How to Check Types in Typescript? Checking types in TypeScript involves methods like typeof for primitive types, instanceof for class instances, and custom type guards for complex type validation. These techniques help ensure variables are correctly typed, improving code safety, and readability, and preventing runtime errors.Here ar 3 min read Like