Invalid number of arguments, expected

Some arguments in the function might have default values. If we don’t pass any arguments into the function, then it will use the default value. So the function will look like:

function doSomethingWithoutPassArgument(optionalArgument){
  optionalArgument = optionalArgument || {};
}

The TypeScript format will be like:

function generateTrackingAttribute(optionalArgument: {[key: string]: any}) {
  optionalArgument = optionalArgument || {};
}

But when you compile by using TypeScript, it will show the error:

Invalid number of arguments, expected XXX arguments

We can set the default value to the arguments to solve this problem

function generateTrackingAttribute(optionalArgument: {[key: string]: any} = {}) {
  optionalArgument = optionalArgument || {};
}

Then compile will be successful.