const sortString = req.query.sort as string
const params = Object.fromEntries(new URLSearchParams(sortString))
Now, when I go to implementation, I get:
declare var URLSearchParams: {
prototype: URLSearchParams;
new(init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
toString(): string;
};
Now, I am confused why it's not working on Typescript, because it should accept a string.
How to convert URL parameters to a JavaScript object?
No overload matches this call.
Overload 1 of 2, '(entries: Iterable<readonly [PropertyKey, any]>): { [k: string]: any; }', gave the following error.
Argument of type 'URLSearchParams' is not assignable to parameter of type 'Iterable<readonly [PropertyKey, any]>'.
Property '[Symbol.iterator]' is missing in type 'URLSearchParams' but required in type 'Iterable<readonly [PropertyKey, any]>'.
Overload 2 of 2, '(entries: Iterable<readonly any[]>): any', gave the following error.
Argument of type 'URLSearchParams' is not assignable to parameter of type 'Iterable<readonly any[]>'.
Property '[Symbol.iterator]' is missing in type 'URLSearchParams' but required in type 'Iterable<readonly any[]>'.ts(2769)