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
2 changes: 1 addition & 1 deletion packages/effect/src/SchemaAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2459,7 +2459,7 @@ function getCandidateTypes(ast: AST): ReadonlyArray<Type> {
case "Objects":
return ast.propertySignatures.length || ast.indexSignatures.length
? ["object"]
: ["object", "array"]
: ["string", "number", "boolean", "symbol", "bigint", "object", "array", "function"]
case "Enum":
return Array.from(new Set(ast.enums.map(([, v]) => typeof v)))
case "Literal":
Expand Down
15 changes: 13 additions & 2 deletions packages/effect/test/schema/Schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4271,15 +4271,26 @@ Expected a value between -2147483648 and 2147483647, got 9007199254740992`
await decoding.fail("a", `Expected exactly one member to match the input "a"`)
})

it("{} & Literal", async () => {
it("Struct({}) preserves its semantics in a union", async () => {
const schema = Schema.Union([
Schema.Struct({}),
Schema.Literal("a")
Schema.Null
])
const asserts = new TestSchema.Asserts(schema)

const decoding = asserts.decoding()
const symbol = Symbol()
const fn = () => {}
await decoding.succeed("a")
await decoding.succeed(1)
await decoding.succeed(true)
await decoding.succeed(symbol)
await decoding.succeed(1n)
await decoding.succeed(fn)
await decoding.succeed({})
await decoding.succeed([])
await decoding.succeed(null)
await decoding.fail(undefined, `Expected object | array | null, got undefined`)
})

describe("should exclude members based on failed sentinels", () => {
Expand Down
Loading