As of now, parsing and validation are both done via getTyped method. This leads to the following drawbacks:
Fallbacks are returned as-is, because they represent parsed values, and there is no way to validate what is already parsed. Therefore, it's possible to specify a fallback that violates validation rules.
Types of useTypedSearchParams could be slightly improved. We can specify initial search params, which behave similarly to fallbacks. If we knew which types don't include validation, we could type the corresponding returned params as non-undefined regardless of the fallbacks of their types. Or we could change useTypedSearchParams to accept actual fallbacks and just validate them.
We could split getTyped into required getTyped and optional validate, but it might be inconvenient for creating custom types.
As of now, parsing and validation are both done via
getTyped
method. This leads to the following drawbacks:useTypedSearchParams
could be slightly improved. We can specify initial search params, which behave similarly to fallbacks. If we knew which types don't include validation, we could type the corresponding returned params as non-undefined
regardless of the fallbacks of their types. Or we could changeuseTypedSearchParams
to accept actual fallbacks and just validate them.We could split
getTyped
into requiredgetTyped
and optionalvalidate
, but it might be inconvenient for creating custom types.Overall, it's not clear which approach is best.