diff --git a/.changeset/cold-actors-drum.md b/.changeset/cold-actors-drum.md new file mode 100644 index 000000000..3a5ed9663 --- /dev/null +++ b/.changeset/cold-actors-drum.md @@ -0,0 +1,5 @@ +--- +"@effect-app/infra": patch +--- + +fix custom error types diff --git a/packages/infra/src/api/routing/DynamicMiddleware.ts b/packages/infra/src/api/routing/DynamicMiddleware.ts index 17ca50968..64be053cf 100644 --- a/packages/infra/src/api/routing/DynamicMiddleware.ts +++ b/packages/infra/src/api/routing/DynamicMiddleware.ts @@ -68,13 +68,17 @@ export type GetEffectError, T> = V } > -type GetFailure1 = F1 extends S.Schema.Any ? F1 : typeof S.Never -type GetFailure = F1 extends S.Schema.Any ? F2 extends S.Schema.Any ? S.Union<[F1, F2]> : F1 : F2 - const merge = (a: any, b: Array) => // eslint-disable-next-line @typescript-eslint/no-unsafe-argument a !== undefined && b.length ? S.Union(a, ...b) : a !== undefined ? a : b.length ? S.Union(...b) : S.Never +// TODO: Fix error types... +type JoinSchema = T extends ReadonlyArray ? S.Union : typeof S.Never +type ExcludeFromTuple = T extends [infer F, ...infer R] + ? [F] extends [E] ? ExcludeFromTuple + : [F, ...ExcludeFromTuple] + : [] + export const makeRpcClient = < RequestConfig extends object, CTXMap extends Record, @@ -96,10 +100,8 @@ export const makeRpcClient = < Tag, { readonly _tag: S.tag } & Payload, typeof config["success"], - | (GetEffectError extends never ? typeof config["failure"] - : GetFailure>) - | GeneralErrors - > // typeof config["failure"] + JoinSchema | GeneralErrors], never>> + > & { config: Omit } ( tag: Tag, @@ -111,8 +113,7 @@ export const makeRpcClient = < Tag, { readonly _tag: S.tag } & Payload, typeof config["success"], - | GetFailure1> - | GeneralErrors + JoinSchema | GeneralErrors], never>> > & { config: Omit } ( @@ -125,8 +126,7 @@ export const makeRpcClient = < Tag, { readonly _tag: S.tag } & Payload, typeof S.Void, - | GetFailure1> - | GeneralErrors + JoinSchema | GeneralErrors], never>> > & { config: Omit } >( @@ -139,8 +139,7 @@ export const makeRpcClient = < Tag, { readonly _tag: S.tag } & Payload, typeof S.Void, - | GetFailure1> - | GeneralErrors + JoinSchema | GeneralErrors], never>> > & { config: Omit } ( @@ -151,7 +150,7 @@ export const makeRpcClient = < Tag, { readonly _tag: S.tag } & Payload, typeof S.Void, - GeneralErrors + GeneralErrors extends never ? typeof S.Never : GeneralErrors > } { // TODO: filter errors based on config + take care of inversion