Skip to content

Commit ebfbbd6

Browse files
support HttpApiError unification (#5818)
1 parent 726ad2c commit ebfbbd6

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

.changeset/upset-animals-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@effect/platform": patch
3+
---
4+
5+
Support `HttpApiError` unification
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { HttpApiError } from "@effect/platform"
2+
3+
import type { Unify } from "effect"
4+
5+
import { describe, expect, it } from "tstyche"
6+
7+
describe("HttpApiError", () => {
8+
describe("Unify", () => {
9+
it("should unify error types", () => {
10+
type testType = Unify.Unify<HttpApiError.NotFound | HttpApiError.RequestTimeout>
11+
expect<testType>()
12+
.type.toBe<HttpApiError.NotFound | HttpApiError.RequestTimeout>()
13+
})
14+
})
15+
})

packages/platform/src/HttpApiSchema.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { hasProperty } from "effect/Predicate"
1212
import * as Schema from "effect/Schema"
1313
import * as AST from "effect/SchemaAST"
1414
import * as Struct from "effect/Struct"
15+
import type * as Unify from "effect/Unify"
1516
import type * as FileSystem from "./FileSystem.js"
1617
import type * as Multipart_ from "./Multipart.js"
1718

@@ -601,12 +602,40 @@ export const deunionize = (
601602
}
602603
}
603604

605+
/**
606+
* @since 1.0.0
607+
* @category empty errors
608+
*/
609+
export interface EmptyError<Self, Tag> extends Effect.Effect<never, Self> {
610+
readonly _tag: Tag
611+
[Unify.typeSymbol]?: unknown
612+
[Unify.unifySymbol]?: EmptyErrorUnify<this>
613+
[Unify.ignoreSymbol]?: EmptyErrorUnifyIgnore
614+
}
615+
616+
/**
617+
* @category models
618+
* @since 1.0.0
619+
*/
620+
export interface EmptyErrorUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
621+
EmptyError?: () => A[Unify.typeSymbol] extends EmptyError<infer Self, infer _Tag> | infer _ ? Self
622+
: never
623+
}
624+
604625
/**
605626
* @since 1.0.0
606627
* @category empty errors
607628
*/
608629
export interface EmptyErrorClass<Self, Tag> extends Schema.Schema<Self, void> {
609-
new(_: void): { readonly _tag: Tag } & Effect.Effect<never, Self>
630+
new(_: void): EmptyError<Self, Tag>
631+
}
632+
633+
/**
634+
* @category models
635+
* @since 1.0.0
636+
*/
637+
export interface EmptyErrorUnifyIgnore extends Effect.EffectUnifyIgnore {
638+
Effect?: true
610639
}
611640

612641
/**

0 commit comments

Comments
 (0)