Looking to fetch paginated data from a server using TypeScript.
Encountering a strange conversion issue with one of the variables.
Created a test program to reproduce the behavior, but it works as expected unlike the main application.
Check out the test program below:
#!/usr/bin/env node
var q = {page: '1', results: '1'};
var si = '1';
interface aqm {
[key: string]: string | number;
}
function uasekq(si: string, q: aqm = {}, foo: string) {
console.log(si);
console.log(q);
console.log(foo);
}
uasekq(si, q, "abc");
Here is how the large application transpiles to JavaScript:
function uasekq(si) {
var q = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
var temp = (0,_cuaq__WEBPACK_IMPORTED_MODULE_0__["default"])((0,_shsosm__WEBPACK_IMPORTED_MODULE_1__["default"])({
queryKey: [
"s",
si,
"aek"
],
pathname: "/v3/keys/storage/:si",
q: (0,_shsospm__WEBPACK_IMPORTED_MODULE_2__["default"])((0,_shsosm__WEBPACK_IMPORTED_MODULE_1__["default"])({}, q), {
si: si
})
}, options));
return temp;
}
The variable q being passed in both the small test program and large application is:
{page: '1', results: '25'}
In the large application, however, q seems to be received differently:
Arguments(2) [undefined, {…}, callee: (...), Symbol(Symbol.iterator): ƒ]
0: undefined
1: {page: '1', results: '25'}
callee: (...)
length: 2
Symbol(Symbol.iterator): ƒ values()
get callee: ƒ ()
set callee: ƒ ()
[[Prototype]]: Object
Here's an excerpt of the original TypeScript function and its call:
// Called with:
// const { d: ek, il } = uasekq(si, q);
// ...from another file.
interface aqm {
[k: string]: string | number;
}
function uasekq(
si: string,
q: aqm = {},
o: p<uaqo<pr<ek>>> = {}
) {
var temp = uaq<pr<ek>>({
qk: ['s', si, 'aek'],
p: '/v/k/s/:si',
q: { ...q, si },
...o,
});
return temp;
}
What could be causing this behavior? It almost looks like an attempt to convert key-value pairs into a numerical array.
We are utilizing [email protected]. Perhaps upgrading to version 5.3.3 might solve the issue? Tried upgrading to TypeScript 5.3.3 but encountered compilation errors. Experimented with [email protected]; successful compilation but bug still persists.