Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service members from Effect.Tag not behaving like normal effects #2745

Closed
arekmaz opened this issue May 14, 2024 · 2 comments · Fixed by #2787
Closed

Service members from Effect.Tag not behaving like normal effects #2745

arekmaz opened this issue May 14, 2024 · 2 comments · Fixed by #2787
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@arekmaz
Copy link

arekmaz commented May 14, 2024

What version of Effect is running?

3.1.4

What steps can reproduce the bug?

given this initial code:

import { Effect } from "effect";

class LoaderArgs extends Effect.Tag("@services/LoaderContext")<
  LoaderArgs,
  { context: number }
>() {}

the LoaderArgs.context is correctly typed as an effect in typescript, and in runtime is present (a function is shown)

however, I cannot do LoaderArgs.context.pipe(... as it throws a runtime exception ("cannot find 'pipe' in undefined")

also this code fails:

Effect.runSync(
  Effect.map(LoaderArgs.context, (ctx) => console.log({ ctx })).pipe(
    Effect.provideService(LoaderArgs, { context: 5 }),
  ),
);

also this code fails:

Effect.runSync(
  Effect.flatMap(LoaderArgs.context, (ctx) => {
    console.log({ ctx });
    return Effect.void;
  }).pipe(Effect.provideService(LoaderArgs, { context: 5 })),
);

with this error:
image

my small repro is in bun, but I first encountered it with node

also, the following ways of expressing the same code work:

Effect.runSync(
  Effect.map(LoaderArgs, ({context: ctx}) => console.log({ ctx })).pipe(
    Effect.provideService(LoaderArgs, { context: 5 }),
  ),
);

and

Effect.runSync(
  LoaderArgs.pipe(
    Effect.map(({ context: ctx }) => console.log({ ctx })),
    Effect.provideService(LoaderArgs, { context: 5 }),
  ),
);

What is the expected behavior?

the code should work (not throw) as with Effect.Tag member services should just be plain effects which work with every mode of map, flatMap etc...

What do you see instead?

image

Additional information

No response

@arekmaz arekmaz added the bug Something isn't working label May 14, 2024
@fubhy
Copy link
Member

fubhy commented May 14, 2024

It would appear that property names that clash with the tag class (so context, of, etc.) are prohibted here.

Merely changing the name from context to something else should work.

./cc @mikearnaldi

@mikearnaldi
Copy link
Member

Yeah it is a name clash, unfortunately Tag already have some members, wondering if we can issue a type error in such cases

@mikearnaldi mikearnaldi added Design Limitation Constraints of the existing architecture prevent this from being fixed and removed bug Something isn't working labels May 20, 2024
@arekmaz arekmaz closed this as completed May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants