fix(typescript-fetch): qualify anyToJSON for any-typed form parameters - #24553
fix(typescript-fetch): qualify anyToJSON for any-typed form parameters#24553donald wants to merge 1 commit into
Conversation
24291b1 to
92cfb62
Compare
|
@donald can you please resolve the merge conflicts when you've time? |
A multipart/form-data parameter with no type at all ("any type") made the
generated apis/*.ts call a bare anyToJSON(...). The file only imports the
runtime as `* as runtime`, so that identifier does not exist and the output
does not compile (TS2304: Cannot find name 'anyToJSON').
formParams.append('meta', new Blob([JSON.stringify(anyToJSON(...))], ...));
The free-form object case already uses runtime.anyToJSON; the any-type case
fell through to {{dataType}}ToJSON, and dataType is `any` for an any-typed
parameter, so it rendered as `anyToJSON`.
Add an isAnyType branch that uses runtime.anyToJSON as well.
Regenerating all 787 sample configs produces no diff.
92cfb62 to
f774057
Compare
|
@wing328 done — rebased onto master and force-pushed (f774057), the conflicts are gone. It was a bit more than context drift: master has since extracted the form-param block out of The second conflict was only both sides appending a test at the same spot — No sample regeneration needed. The only typescript-fetch sample that reaches that line is |
Fixes #24552
What
A
multipart/form-dataparameter with no type at all ("any type") made the generatedapis/*.tscalla bare
anyToJSON(...). The file only imports the runtime as* as runtime, so that identifier does notexist and the output does not compile.
Why
apis.mustache#L288:The free-form object case (added with
anyToJSONin #1877) is qualified correctly. The any-type case fallsthrough to
{{dataType}}ToJSON, and for an any-typed parameterdataTypeisany, so it renders as theunqualified
anyToJSON.How
Add an
isAnyTypebranch that also usesruntime.anyToJSON. Everything else keeps rendering{{dataType}}ToJSONexactly as before.Testing
TypeScriptFetchClientCodegenTest.testAnyTypeFormParamUsesQualifiedAnyToJSON— asserts the generatedcall is namespace-qualified and that the bare form is gone. Verified that this test fails without the
fix (
does not contain line [runtime.anyToJSON(requestParameters['meta'])]).TypeScriptFetchClientCodegenTest(35 tests) passes../bin/generate-samples.sh ./bin/configs/*.yaml) and./bin/utils/export_docs_generators.sh— no diff. No existing sample has an any-typed formparameter, which is why this went unnoticed.
PR checklist
(Both scripts were run; neither produced any change, so there is nothing to commit beyond the fix and its test.)
masterTypeScript technical committee:
@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka @joscha
🤖 Generated with Claude Code
Summary by cubic
Qualifies
anyToJSONasruntime.anyToJSONfor multipart/form-data parameters with no type intypescript-fetchclients. Previously the template emitted a bareanyToJSON(...), causing a compile error; now it uses the runtime-qualified call and other cases still use{{dataType}}ToJSON.apisFormParams.mustacheto useruntime.anyToJSONwhenisAnyTypeis true; preserve existingisFreeFormObjectand default{{dataType}}ToJSONpaths.testAnyTypeFormParamUsesQualifiedAnyToJSONwithany-type-form-param.yaml.Written for commit f774057. Summary will update on new commits.