Sometimes we want to get the data type of arguments in a constructor in a class to serve a certain purpose. To do this, we will use ConstructorParameters. Let’s get started.
Ways to get the type of a constructor function arguments in TypeScript
To be able to get the data type of the constructor function’s arguments, TypeScript has provided some methods in the new version. TypeScript has provided ConstructorParameters for us to do this the same way as Parameters. We will use it with the typeof keyword. Make sure you pass in a class instead of an object of the class.
Using ConstructorParameters
Using this method, you will get an array or a tuple containing the data types of constructor function arguments. This method has been updated in the TypeScript 3.1 version. You can use the following syntax.
Syntax:
type typeOfConstructor = ConstructorParameters<typeof className>;
Parameter:
className
: this is the name of the class containing the constructor that you want to get the data type of arguments
Return Value
Variable typeOfConstructor
will contain an array or a tuple containing the data types of the arguments in the constructor.
Example:
class Car { constructor( public manufacturer: string, public price: number, public model: string ) { this.manufacturer = manufacturer; this.price = price; this.model = model; } } // Using ConstructorParameters to get the data type of the constructor function arguments type CarType = ConstructorParameters<typeof Car>; const myCar: CarType = ["Honda", 199000, "Hatch Back"]; console.log(myCar);
Output:
["Honda", 199000, "Hatch Back"]
In the above example, we declare a class named Car
which includes a constructor consisting of 3 arguments which respectively have data types of string and number. Now, if we want to get the data type of this constructor, we will declare a type named CarType
and will use ConstructorParameters. We will pass in the name of the class and add the typeof keyword. Now the return data assigned in the CarType
variable will be an array with the data type in each element. To illustrate the example, we create an array of data type CarType
and assign it to the variable myCar
.
Regular function
In case it is not a constructor function arguments of a class but a regular function, we will use the Parameters utility type.
Example:
const getCar = (manufacturer: string, price: number, model: string) => { return `${manufacturer}${price}${model}`; }; // We use Parameters utility type in case a regular function type CarType = Parameters<typeof getCar>; const myCar: CarType = ["Honda", 199000, "Hatch Back"]; console.log(myCar);
Output:
["Honda", 199000, "Hatch Back"]
Summary
So we already know how to get the type of a constructor function arguments in TypeScript using ConstructorParameters. Note that you have to pass in the name of the class and not an object of the class. We hope this article is helpful for you.

Carolyn Hise has three years of software development expertise. Strong familiarity with the following languages is required: Python, Typescript/Nodejs, .Net, Java, C++, and a strong foundation in Object-oriented programming (OOP).