Skip to content

Commit

Permalink
fix: bug with persist
Browse files Browse the repository at this point in the history
  • Loading branch information
gearonix committed Feb 14, 2024
1 parent 217d9b2 commit e7cd0a1
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ type SerializeMiddlewareKeys<
>(
initializer: StateCreator<
T,
[...Mps, [infer MutatorValue extends StoreMutatorIdentifier, never]],
[...Mps, [infer MutatorValue extends StoreMutatorIdentifier, infer _]],
Mcs
>,
options?: Record<string, unknown>
) => StateCreator<T, Mps, [[StoreMutatorIdentifier, never], ...Mcs]>
options?: any
) => StateCreator<T, Mps, [[StoreMutatorIdentifier, any], ...Mcs]>
? SerializeMiddlewareKeys<Rest, [...Result, [MutatorValue, never]]>
: never
: Result
Expand Down Expand Up @@ -96,14 +96,8 @@ type ExtractMiddlewareName<

type PrintErrorMessage<
M extends MiddlewareOrOptions,
Extracted extends AnyMiddleware = ExtractMiddleware<M>,
Serialized extends [
StoreMutatorIdentifier,
never
][] = SerializeMiddlewareKeys<[Extracted]>
> = Serialized[0] extends [infer Property extends string, ...infer _]
? WrongOptionsException<Property>
: never
Extracted extends AnyMiddleware = ExtractMiddleware<M>
> = WrongOptionsException<ExtractMiddlewareName<Extracted>>

type HasCorrectMiddlewareOptions<M extends MiddlewareOrOptions[]> = Extract<
TupleToUnion<{
Expand All @@ -116,7 +110,7 @@ type HasCorrectMiddlewareOptions<M extends MiddlewareOrOptions[]> = Extract<
string
>

interface CreateWithMiddlewares<M extends AnyMiddleware[]> {
interface PipeMiddlewares<M extends AnyMiddleware[]> {
<
T,
Mos extends [StoreMutatorIdentifier, unknown][] = Reverse<
Expand Down Expand Up @@ -177,7 +171,7 @@ interface Configure {
>(
...middlewares: Raw
): [MaybeError] extends [never]
? CreateWithMiddlewares<ExtractMiddlewares<Raw>>
? PipeMiddlewares<ExtractMiddlewares<Raw>>
: MaybeError
}

Expand All @@ -189,15 +183,10 @@ const isOptionsWithCreator = (
const isOptionsWithoutCreator = (raw: unknown): raw is Omit<AnyObj, 'impl'> =>
isObject(raw) && !hasOwn(raw, 'impl')

function extractMiddlewareAndOptions(
const extractMiddlewareAndOptions = (
middlewareOrOpts: MiddlewareOrOptions
): MiddlewareAndOptions {
if (isFunction(middlewareOrOpts)) {
return [middlewareOrOpts, null]
}

return middlewareOrOpts
}
): MiddlewareAndOptions =>
isFunction(middlewareOrOpts) ? [middlewareOrOpts, null] : middlewareOrOpts

function pipeMiddlewares(
options: AnyObj,
Expand Down

0 comments on commit e7cd0a1

Please sign in to comment.