Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/upset-animals-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform": patch
---

Support `HttpApiError` unification
15 changes: 15 additions & 0 deletions packages/platform/dtslint/HttpApiError.tst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { HttpApiError } from "@effect/platform"

import type { Unify } from "effect"

import { describe, expect, it } from "tstyche"

describe("HttpApiError", () => {
describe("Unify", () => {
it("should unify error types", () => {
type testType = Unify.Unify<HttpApiError.NotFound | HttpApiError.RequestTimeout>
expect<testType>()
.type.toBe<HttpApiError.NotFound | HttpApiError.RequestTimeout>()
})
})
})
31 changes: 30 additions & 1 deletion packages/platform/src/HttpApiSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { hasProperty } from "effect/Predicate"
import * as Schema from "effect/Schema"
import * as AST from "effect/SchemaAST"
import * as Struct from "effect/Struct"
import type * as Unify from "effect/Unify"
import type * as FileSystem from "./FileSystem.js"
import type * as Multipart_ from "./Multipart.js"

Expand Down Expand Up @@ -601,12 +602,40 @@ export const deunionize = (
}
}

/**
* @since 1.0.0
* @category empty errors
*/
export interface EmptyError<Self, Tag> extends Effect.Effect<never, Self> {
readonly _tag: Tag
[Unify.typeSymbol]?: unknown
[Unify.unifySymbol]?: EmptyErrorUnify<this>
[Unify.ignoreSymbol]?: EmptyErrorUnifyIgnore
}

/**
* @category models
* @since 1.0.0
*/
export interface EmptyErrorUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
EmptyError?: () => A[Unify.typeSymbol] extends EmptyError<infer Self, infer _Tag> | infer _ ? Self
: never
}

/**
* @since 1.0.0
* @category empty errors
*/
export interface EmptyErrorClass<Self, Tag> extends Schema.Schema<Self, void> {
new(_: void): { readonly _tag: Tag } & Effect.Effect<never, Self>
new(_: void): EmptyError<Self, Tag>
}

/**
* @category models
* @since 1.0.0
*/
export interface EmptyErrorUnifyIgnore extends Effect.EffectUnifyIgnore {
Effect?: true
}

/**
Expand Down