You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionsearchPets(foo: string|null,bar?: string|null){returnpetService.searchPets({ foo, bar });}
Calling searchPets("test") will result in <url>?foo=test&bar=undefined
That's undesirable - IMO
The solution
I think it's safe to assume that foo= and baz=undefined can be stripped.
We could trim the parameters.
or
We could make a hook-thingy so users can transform/mutate api parameters.
Alternative
I tried trimming the parameters, but it leads to either unsafe parameter parsing or verbose code
functionsearchPets(foo: string|null,bar?: string|null){// doesntBelong is not flagged as an invalid parameterreturnpetService.searchPets(myTrimFn({ foo, bar,doesntBelong: 1}));// here I have to import SearchPetsParams and manually add it to myTrimFnconstparams=myTrimFn<SearchPetsParams>({ foo, bar,doesntBelong: 1});// yay, doesntBelong is flagged as invalidreturnpetService.searchPets(params);}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I've got an interesting (annoying actually) problem. It basically boils down to the way
URLSearchParams
works.Example
The
foo=
andbaz=undefined
is rather unexpected - at least for meThe problem
Lets say we have the following client generated by orval
In my app I have this
Calling
searchPets("test")
will result in<url>?foo=test&bar=undefined
That's undesirable - IMO
The solution
I think it's safe to assume that
foo=
andbaz=undefined
can be stripped.We could trim the parameters.
or
We could make a hook-thingy so users can transform/mutate api parameters.
Alternative
I tried trimming the parameters, but it leads to either unsafe parameter parsing or verbose code
Beta Was this translation helpful? Give feedback.
All reactions