Replies: 3 comments 2 replies
-
Yeah, the initial intention was to restrict to numbers and strings to avoid assigning to arrays or other types. But, I agree that thta's a valid use case. It's one line change so I'll release a patch with beta tag for now. |
Beta Was this translation helpful? Give feedback.
-
@OwenVey just released a beta version for this update (@better-fetch/[email protected]). Previously, we didn't validate parameters, body, or query. They were only used for type inference. Now, it should work. Plus params can be any zod schema. Let me know if you run into any issues. |
Beta Was this translation helpful? Give feedback.
-
Updated to params: z.object({
countryCode: z.string().default('global'),
}), works now but the params: z
.object({
countryCode: z.string().default('global'),
})
.optional(), but then I get a TS error on
In a perfect world, it would be nice to just be able to define my Edit: I forgot that zod handles not making things required if const data = await $fetch('/rankings/:countryCode/players', { params: {} }); which isn't ideal. |
Beta Was this translation helpful? Give feedback.
-
I have an endpoint like
/rankings/:countryCode/players
, and I was wondering if it's possible to make thecountryCode
parameter more specific than justz.string()
. For example, it would be great if we could define it like this:Currently, even with:
I get the following TS error
I'm not sure if this is a bug or a current limitation of
params
, but I think it would be a great quality-of-life feature to allow more specific parameter definitions with defaults. I’m also curious how this would work with number types and others, given that everything in the URL ends up being a string. Just an idea to consider!Beta Was this translation helpful? Give feedback.
All reactions