TypeScript is not like JavaScript. When you want to pass an object into a function, you must specify the data type of that object. Otherwise, the Binding element ‘#’ implicitly has an ‘any’ type error will appear. This article will show error situations and how to fix them.
Cause of error Binding element ‘#’ implicitly has an ‘any’ type in TypeScript
The error occurs because the parameter in a function accepts an object of an undetermined data type.
Example:
// The object passed to the function has not been specified with a data type function GetStudent({ name, age }) { return { name, age }; }
In the above example, we declare the GetStudent
function, and we pass an object as { name, age }
, but the error will occur if this object has not been defined as a data type. Because TypeScript has very tight control over the data of the object. Let’s look at the next example where the error occurs in the class definition.
Example:
class Car { manufacturer: string; price: number; // We pass in the constructor an object without specifying the data type constructor({ manufacturer, price }) { this.manufacturer = manufacturer; this.price = price; } }
In the example of class, we declare a Car class that includes the properties manufacturer and price, these two properties are defined as data types, but the constructor of this class accepts an object that has no defined data type, and the error occurs.
How to solve Binding element ‘#’ implicitly has an ‘any’ type in TypeScript
In TypeScript, we have to specify the data type of the object that passed to the function. We will fix the above by adding a colon to separate the two parts. One part is the parameter, and the other part is the data type of the parameter.
For the function
// Specify the data type of the object that passed to the function function GetStudent({ name, age }: { name: string; age: number }) { return { name, age }; }
We add to the function the following code “: {name: string, age: number}"
. This is the description of the data type of the object that we pass in the function.
For the class
class Car { manufacturer: string; price: number; constructor({ manufacturer, price, }: { // Specify the data type of the object that passed to the constructor manufacturer: string; price: number; }) { this.manufacturer = manufacturer; this.price = price; } }
Similar to the function, we will add the following code “: {manufacturer: string; price: number;}
“, but for the class, we add to the constructor and the methods of the class.
Summary
Through this article, we have presented error situations and how to fix them in different circumstances. Just keep in mind that a colon-separated data type must be added when you need a function that takes an object as a parameter. Hope you will quickly resolve the error. Thanks for reading.

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).