Error Extending `Data.TaggedError` Class in TypeScript
I have a weird issue.
Since the
Data.TaggedError
Data.TaggedError
itself cannot be extended the way I want because of
TS4023: Exported variable X has or is using name Y from external module
TS4023: Exported variable X has or is using name Y from external module
, I tried to copy/paste the code from the Effect repository.
However, even when leaving the code untouched:
/** * Original Data.TaggedError class can be found here: * * @see https://github.com/Effect-TS/effect/blob/35a0f813141652d696461cd5d19fd146adaf85be/packages/effect/src/Data.ts#L552 */const ErrorBase = <Tag extends string>( tag: Tag,): new <A extends Record<string, any> = {}>( args: Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] },) => Cause.YieldableError & { readonly _tag: Tag } & Readonly<A> => { class Base extends Error<{}> { readonly _tag = tag; } (Base.prototype as any).name = tag; return Base as any;};
/** * Original Data.TaggedError class can be found here: * * @see https://github.com/Effect-TS/effect/blob/35a0f813141652d696461cd5d19fd146adaf85be/packages/effect/src/Data.ts#L552 */const ErrorBase = <Tag extends string>( tag: Tag,): new <A extends Record<string, any> = {}>( args: Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] },) => Cause.YieldableError & { readonly _tag: Tag } & Readonly<A> => { class Base extends Error<{}> { readonly _tag = tag; } (Base.prototype as any).name = tag; return Base as any;};
I get a:
Error: BUG: FiberRuntime - {
Error: BUG: FiberRuntime - {
How in the world is it working when I import it from the package, but fails to work when I use it as raw code