TS7031

error TS7031: Binding element ‘age’ implicitly has an ‘any’ type.

Broken Code ❌

1
2
3
export function printAge({age}): void {
console.log(age);
}

Fixed Code ✔️

TypeScript complains because it doesn’t know the type of the argument that we are destructuring. That’s why it sets all
its properties to the type of any. To prevent that we have to define a type for the parameter of the printAge
function:

1
2
3
4
5
6
7
8
type Person = {
age: number;
name: string;
}

export function printAge({age}: Person): void {
console.log(age);
}