fix(typescript-fetch): qualify anyToJSON for any-typed form parameters - #24553
Open
donald wants to merge 1 commit into
Open
fix(typescript-fetch): qualify anyToJSON for any-typed form parameters#24553donald wants to merge 1 commit into
donald wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Fixes a compile error in generated
typescript-fetchclients when a multipart/form-data param has no type by qualifyinganyToJSONasruntime.anyToJSON. Generated clients now compile in this case.runtime.anyToJSONforisAnyTypeform params; other cases still use{{dataType}}ToJSON.testAnyTypeFormParamUsesQualifiedAnyToJSON.Written for commit 24291b1. Summary will update on new commits.