Skip to content

Commit b917236

Browse files
authored
fix(fetch): type error caused by useDates date param string coerce (#3384)
* fix(fetch,solid-start): use String() for non-Date query param coercion * test(snapshots): refresh URL builder snapshots for String() coercion * fix: two straggler snapshots * fix: all the snapshots, hopefully
1 parent cd010a4 commit b917236

131 files changed

Lines changed: 382 additions & 232 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/fetch/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export const generateRequestFunction = (
145145
146146
if (Array.isArray(value) && explodeParameters.includes(key)) {
147147
value.forEach((v) => {
148-
normalizedParams.append(key, v === null ? 'null' : ${hasExplodedDateParams ? 'v instanceof Date ? v.toISOString() : ' : ''}v.toString());
148+
normalizedParams.append(key, v === null ? 'null' : ${hasExplodedDateParams ? 'v instanceof Date ? v.toISOString() : ' : ''}String(v));
149149
});
150150
return;
151151
}
@@ -167,7 +167,7 @@ export const generateRequestFunction = (
167167
});
168168

169169
const normalParamsImplementation = `if (value !== undefined) {
170-
normalizedParams.append(key, value === null ? 'null' : ${hasDateParams ? 'value instanceof Date ? value.toISOString() : ' : ''}value.toString())
170+
normalizedParams.append(key, value === null ? 'null' : ${hasDateParams ? 'value instanceof Date ? value.toISOString() : ' : ''}String(value))
171171
}`;
172172

173173
const getUrlFnImplementation = `export const ${getUrlFnName} = (${getUrlFnProps}) => {

packages/solid-start/src/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,7 @@ describe('generateSolidStart — query string serialization', () => {
389389
expect(implementation).toContain('const explodeParameters = ["country"]');
390390
expect(implementation).toContain('Array.isArray(value)');
391391
// scalar fallback still present (the ternary after the Array.isArray branch)
392-
expect(implementation).toContain(
393-
"value === null ? 'null' : value.toString()",
394-
);
392+
expect(implementation).toContain("value === null ? 'null' : String(value)");
395393
});
396394

397395
it('generates per-element append for an array param declared via oneOf', async () => {

packages/solid-start/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,15 @@ const generateImplementation = (
289289
290290
if (Array.isArray(value) && explodeParameters.includes(key)) {
291291
value.forEach((v) => {
292-
normalizedParams.append(key, v === null ? 'null' : ${hasExplodedDateParams ? 'v instanceof Date ? v.toISOString() : ' : ''}v.toString());
292+
normalizedParams.append(key, v === null ? 'null' : ${hasExplodedDateParams ? 'v instanceof Date ? v.toISOString() : ' : ''}String(v));
293293
});
294294
return;
295295
}
296296
`
297297
: '';
298298

299299
const normalParamsImplementation = `if (value !== undefined) {
300-
normalizedParams.append(key, Array.isArray(value) ? value.map(v => v === null ? 'null' : ${hasDateParams ? 'v instanceof Date ? v.toISOString() : ' : ''}String(v)).join(',') : value === null ? 'null' : ${hasDateParams ? 'value instanceof Date ? value.toISOString() : ' : ''}value.toString())
300+
normalizedParams.append(key, Array.isArray(value) ? value.map(v => v === null ? 'null' : ${hasDateParams ? 'v instanceof Date ? v.toISOString() : ' : ''}String(v)).join(',') : value === null ? 'null' : ${hasDateParams ? 'value instanceof Date ? value.toISOString() : ' : ''}String(value))
301301
}`;
302302

303303
// Build query params string

samples/hono/hono-with-fetch-client/__snapshots__/next-app/pets/pets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const getListPetsUrl = (params?: ListPetsParams) => {
6969

7070
Object.entries(params || {}).forEach(([key, value]) => {
7171
if (value !== undefined) {
72-
normalizedParams.append(key, value === null ? 'null' : value.toString());
72+
normalizedParams.append(key, value === null ? 'null' : String(value));
7373
}
7474
});
7575

samples/hono/hono-with-fetch-client/next-app/app/gen/pets/pets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const getListPetsUrl = (params?: ListPetsParams) => {
6969

7070
Object.entries(params || {}).forEach(([key, value]) => {
7171
if (value !== undefined) {
72-
normalizedParams.append(key, value === null ? 'null' : value.toString());
72+
normalizedParams.append(key, value === null ? 'null' : String(value));
7373
}
7474
});
7575

samples/mcp/custom-server/src/http-client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const getFindPetsByStatusUrl = (params?: FindPetsByStatusParams) => {
108108

109109
Object.entries(params || {}).forEach(([key, value]) => {
110110
if (value !== undefined) {
111-
normalizedParams.append(key, value === null ? 'null' : value.toString());
111+
normalizedParams.append(key, value === null ? 'null' : String(value));
112112
}
113113
});
114114

@@ -192,7 +192,7 @@ export const getFindPetsByTagsUrl = (params?: FindPetsByTagsParams) => {
192192

193193
if (Array.isArray(value) && explodeParameters.includes(key)) {
194194
value.forEach((v) => {
195-
normalizedParams.append(key, v === null ? 'null' : v.toString());
195+
normalizedParams.append(key, v === null ? 'null' : String(v));
196196
});
197197
return;
198198
}
@@ -353,7 +353,7 @@ export const getUpdatePetWithFormUrl = (
353353

354354
Object.entries(params || {}).forEach(([key, value]) => {
355355
if (value !== undefined) {
356-
normalizedParams.append(key, value === null ? 'null' : value.toString());
356+
normalizedParams.append(key, value === null ? 'null' : String(value));
357357
}
358358
});
359359

@@ -675,7 +675,7 @@ export const getLoginUserUrl = (params?: LoginUserParams) => {
675675

676676
Object.entries(params || {}).forEach(([key, value]) => {
677677
if (value !== undefined) {
678-
normalizedParams.append(key, value === null ? 'null' : value.toString());
678+
normalizedParams.append(key, value === null ? 'null' : String(value));
679679
}
680680
});
681681

samples/mcp/petstore/src/http-client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const getFindPetsByStatusUrl = (params?: FindPetsByStatusParams) => {
108108

109109
Object.entries(params || {}).forEach(([key, value]) => {
110110
if (value !== undefined) {
111-
normalizedParams.append(key, value === null ? 'null' : value.toString());
111+
normalizedParams.append(key, value === null ? 'null' : String(value));
112112
}
113113
});
114114

@@ -192,7 +192,7 @@ export const getFindPetsByTagsUrl = (params?: FindPetsByTagsParams) => {
192192

193193
if (Array.isArray(value) && explodeParameters.includes(key)) {
194194
value.forEach((v) => {
195-
normalizedParams.append(key, v === null ? 'null' : v.toString());
195+
normalizedParams.append(key, v === null ? 'null' : String(v));
196196
});
197197
return;
198198
}
@@ -353,7 +353,7 @@ export const getUpdatePetWithFormUrl = (
353353

354354
Object.entries(params || {}).forEach(([key, value]) => {
355355
if (value !== undefined) {
356-
normalizedParams.append(key, value === null ? 'null' : value.toString());
356+
normalizedParams.append(key, value === null ? 'null' : String(value));
357357
}
358358
});
359359

@@ -675,7 +675,7 @@ export const getLoginUserUrl = (params?: LoginUserParams) => {
675675

676676
Object.entries(params || {}).forEach(([key, value]) => {
677677
if (value !== undefined) {
678-
normalizedParams.append(key, value === null ? 'null' : value.toString());
678+
normalizedParams.append(key, value === null ? 'null' : String(value));
679679
}
680680
});
681681

samples/next-app-with-fetch/__snapshots__/pets/pets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const getListPetsUrl = (params?: ListPetsParams) => {
9999

100100
Object.entries(params || {}).forEach(([key, value]) => {
101101
if (value !== undefined) {
102-
normalizedParams.append(key, value === null ? 'null' : value.toString());
102+
normalizedParams.append(key, value === null ? 'null' : String(value));
103103
}
104104
});
105105

samples/next-app-with-fetch/app/gen/pets/pets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const getListPetsUrl = (params?: ListPetsParams) => {
9999

100100
Object.entries(params || {}).forEach(([key, value]) => {
101101
if (value !== undefined) {
102-
normalizedParams.append(key, value === null ? 'null' : value.toString());
102+
normalizedParams.append(key, value === null ? 'null' : String(value));
103103
}
104104
});
105105

samples/react-app-with-swr/basic/__snapshots__/endpoints/petstoreFromFileSpecWithTransformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const getListPetsUrl = (
9191

9292
Object.entries(params || {}).forEach(([key, value]) => {
9393
if (value !== undefined) {
94-
normalizedParams.append(key, value === null ? 'null' : value.toString());
94+
normalizedParams.append(key, value === null ? 'null' : String(value));
9595
}
9696
});
9797

0 commit comments

Comments
 (0)