Description
private addQueryParams(query: object): string {
const keys = Object.keys(query);
return keys.length ? (
'?' +
keys.reduce((paramsArray, param) => [
...paramsArray,
param + '=' + encodeURIComponent(query[param])
], []).join('&')
) : ''
}
(parameter) param: string
No overload matches this call.
Overload 1 of 3, '(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string', gave the following error.
Type 'string[]' is not assignable to type 'string'.
Overload 2 of 3, '(callbackfn: (previousValue: never[], currentValue: string, currentIndex: number, array: string[]) => never[], initialValue: never[]): never[]', gave the following error.
Type 'string[]' is not assignable to type 'never[]'.
Type 'string' is not assignable to type 'never'.ts(2769)
lib.es5.d.ts(1350, 24): The expected type comes from the return type of this signature.
lib.es5.d.ts(1356, 27): The expected type comes from the return type of this signature.
I suggest following code:
private addQueryParams(query: {[key:string]:string|number|boolean}): string {
const keys = Object.keys(query);
return keys.length === 0 ? ''
: '?' + keys.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(query[key])).join('&')
}