defineQuerySchema @vuqs/core
Names a reusable schema, normalized so its type stays stable across composables and typeof derivations.
Usage
ts
import { codecs, defineQuerySchema, queryParam } from '@vuqs/core'
export const filters = defineQuerySchema({
q: codecs.string,
status: queryParam('status', codecs.literal(['open', 'closed'] as const)),
})Type
ts
function defineQuerySchema<const TSchema extends QueryStateSchemaInput>(schema: TSchema): NormalizeQueryStateSchema<TSchema>Parameters
schema: TSchema- A map of logical name to a codec or a
queryParamdefinition, the same inputuseQueryStatesaccepts.
- A map of logical name to a codec or a
Return value
schema: NormalizeQueryStateSchema<TSchema>- The schema with codec-shorthand entries normalized to
DefinedQueryParam. Pass it touseQueryStatesorcreateSerializer, and derive value types withQueryStateValues<typeof schema>.
- The schema with codec-shorthand entries normalized to
NormalizeQueryStateSchema
ts
type NormalizeQueryStateSchema<TSchema extends QueryStateSchemaInput> = {
[Key in keyof TSchema]: TSchema[Key] extends AnyDefinedQueryParam
? TSchema[Key]
: TSchema[Key] extends Codec<infer TValue>
? TSchema[Key] extends { readonly defaultValue: TValue }
? DefinedQueryParam<TValue, TValue, TValue, true>
: DefinedQueryParam<TValue, TValue, TValue, false>
: never
}