Skip to content

Commit

Permalink
fix: Parser builder requires a serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Sep 12, 2023
1 parent dd4a2b6 commit 432ed56
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type Parser<T> = {
serialize?: (value: T) => string
}

export type ParserBuilder<T> = Parser<T> &
export type ParserBuilder<T> = Required<Parser<T>> &
Options & {
/**
* Set history type, shallow routing and scroll restoration options
Expand All @@ -16,7 +16,9 @@ export type ParserBuilder<T> = Parser<T> &
*/
withOptions(
options: Options
): Parser<T> & Readonly<Options> & Pick<ParserBuilder<T>, 'withDefault'>
): Required<Parser<T>> &
Readonly<Options> &
Pick<ParserBuilder<T>, 'withDefault'>

/**
* Specifying a default value makes the hook state non-nullable when the
Expand All @@ -27,7 +29,7 @@ export type ParserBuilder<T> = Parser<T> &
*
* @param defaultValue
*/
withDefault(defaultValue: NonNullable<T>): Parser<T> &
withDefault(defaultValue: NonNullable<T>): Required<Parser<T>> &
Options & {
readonly defaultValue: NonNullable<T>

Expand Down Expand Up @@ -69,7 +71,7 @@ export type ParserBuilder<T> = Parser<T> &
* Wrap a set of parse/serialize functions into a builder pattern parser
* you can pass to one of the hooks, making its default value type safe.
*/
export function createParser<T>(parser: Parser<T>): ParserBuilder<T> {
export function createParser<T>(parser: Required<Parser<T>>): ParserBuilder<T> {
return {
...parser,
parseServerSide(value = '') {
Expand Down

0 comments on commit 432ed56

Please sign in to comment.