effect
effect copied to clipboard
Type reference error in `Schema.Union`
What version of Effect is running?
No response
What steps can reproduce the bug?
clone https://github.com/ethanniser/effect-schema-type-bug
bun i
bun run t
observe error
(uncomment line in pkg/src/index.ts)
bun run t
observe working
What is the expected behavior?
the build succeeds
What do you see instead?
src/index.ts(3,14): error TS4023: Exported variable 'ErrorSchema' has or is using name 'Channel' from external module "/Users/ethan/src/temp/effect-schema-type-bug/node_modules/effect/dist/dts/Cause" but cannot be named.
src/index.ts(3,14): error TS4023: Exported variable 'ErrorSchema' has or is using name 'Effect' from external module "/Users/ethan/src/temp/effect-schema-type-bug/node_modules/effect/dist/dts/Cause" but cannot be named.
src/index.ts(3,14): error TS4023: Exported variable 'ErrorSchema' has or is using name 'NodeInspectSymbol' from external module "/Users/ethan/src/temp/effect-schema-type-bug/node_modules/effect/dist/dts/Inspectable" but cannot be named.
src/index.ts(3,14): error TS4023: Exported variable 'ErrorSchema' has or is using name 'RefineSchemaId' from external module "/Users/ethan/src/temp/effect-schema-type-bug/node_modules/effect/dist/dts/Schema" but cannot be named.
src/index.ts(3,14): error TS4023: Exported variable 'ErrorSchema' has or is using name 'Sink' from external module "/Users/ethan/src/temp/effect-schema-type-bug/node_modules/effect/dist/dts/Cause" but cannot be named.
src/index.ts(3,14): error TS4023: Exported variable 'ErrorSchema' has or is using name 'Stream' from external module "/Users/ethan/src/temp/effect-schema-type-bug/node_modules/effect/dist/dts/Cause" but cannot be named.
src/index.ts(3,14): error TS4023: Exported variable 'ErrorSchema' has or is using name 'TypeId' from external module "/Users/ethan/src/temp/effect-schema-type-bug/node_modules/effect/dist/dts/Schema" but cannot be named.
Error: error occurred in dts build
at Worker.<anonymous> (/Users/ethan/src/temp/effect-schema-type-bug/node_modules/tsup/dist/index.js:1545:26)
at Worker.emit (node:events:518:28)
at MessagePort.<anonymous> (node:internal/worker:268:53)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:827:20)
at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)
DTS Build error
error: script "t" exited with code 1
Additional information
No response
The union members will need to be exported otherwise TS has no idea how to name such types:
import { Schema } from "effect";
export class FooError extends Schema.TaggedError<FooError>()("FooError", {
cause: Schema.optional(Schema.Unknown),
}) {}
export const Errors = Schema.Union(FooError);
This would be the correct way to do it
ran into a similar issue just now, and exporting my custom tagged error (even though it's not used directly outside of the file it's defined in) fixed the issue for me