I have a function that manipulates a specified query string, along with another version that always uses window.location.search
. Here is the code snippet:
class MyClass {
public changeQuery(query: string; exclude: boolean = true; ...values: string[]): string {
// code logic here
}
public getQuery(exclude: boolean = true; ...values: string[]): string {
let args: any[] = [...values];
args.unshift(exclude);
args.unshift(window.location.search);
return this.changeQuery.apply(this, args); // <-- Error occurs @args
}
}
An error message is appearing:
Argument of type 'any[]' is not assignable to parameter of type '[string, (boolean | undefined)?, ...string[]]'. Property '0' is missing in type 'any[]' but required in type '[string, (boolean | undefined)?, ...string[]]'.
To resolve this issue, I believe the variable let args
needs to be defined differently. But what would be the correct definition? Alternatively, is it possible to make the parameter query: string
optional in the updateQuery
function and set it as window.location.search
if no value is provided?