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/curly-mice-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Add test for ensuring typeConstructor is attached
1 change: 1 addition & 0 deletions packages/effect/src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ interface AllAnnotations<A, TypeParameters extends ReadonlyArray<any>>
{}

const builtInAnnotations = {
typeConstructor: AST.TypeConstructorAnnotationId,
schemaId: AST.SchemaIdAnnotationId,
message: AST.MessageAnnotationId,
missingMessage: AST.MissingMessageAnnotationId,
Expand Down
12 changes: 12 additions & 0 deletions packages/effect/test/Schema/Schema/annotations.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, it } from "@effect/vitest"
import { assertTrue, deepStrictEqual, strictEqual } from "@effect/vitest/utils"
import * as Option from "effect/Option"
import type * as ParseResult from "effect/ParseResult"
import type * as Pretty from "effect/Pretty"
import * as S from "effect/Schema"
Expand Down Expand Up @@ -81,6 +82,17 @@ describe(".annotations()", () => {
})
})

it("typeConstructor", () => {
const schema = S.Struct({ a: S.String }).annotations({ typeConstructor: { _tag: "MyTypeConstructor" } })
deepStrictEqual(schema.ast.annotations, {
[AST.TypeConstructorAnnotationId]: { _tag: "MyTypeConstructor" }
})
deepStrictEqual(
AST.getTypeConstructorAnnotation(schema.ast),
Option.some({ _tag: "MyTypeConstructor" })
)
})

it("parseIssueTitle", async () => {
const getOrderId = ({ actual }: ParseResult.ParseIssue) => {
if (S.is(S.Struct({ id: S.Number }))(actual)) {
Expand Down