When wanting to share a Schema between the client and server it would make sense to declare it once in a shared location and then pass it to both queryParamsState and parseURL.
However, 1) without Schema being exported we can't get any type information while writing our schema, and more importantly 2) the inferred Typescript type is too wide and not assignable to Schema. Consider the following schema:
export const schema = {
search: 'string'
}
This has the inferred type
const schema: {
search: string;
}
Which is too wide. In this example, string is not assignable to the Primitive type which is much more specific. Exporting Schema and using it in the schema declaration fixes this. Declaring the schema as const also fully narrows the type, but all of the properties resulting from queryParamsState are then readonly which isn't very useful.
I can make a PR if you would like but I'm not sure what other types, if any, should be publicly exported.
Thanks for the library
When wanting to share a
Schemabetween the client and server it would make sense to declare it once in a shared location and then pass it to bothqueryParamsStateandparseURL.However, 1) without
Schemabeing exported we can't get any type information while writing our schema, and more importantly 2) the inferred Typescript type is too wide and not assignable toSchema. Consider the following schema:This has the inferred type
Which is too wide. In this example,
stringis not assignable to thePrimitivetype which is much more specific. ExportingSchemaand using it in the schema declaration fixes this. Declaring the schemaas constalso fully narrows the type, but all of the properties resulting fromqueryParamsStateare then readonly which isn't very useful.I can make a PR if you would like but I'm not sure what other types, if any, should be publicly exported.
Thanks for the library