Effect CommunityEC
Effect Community2y ago
62 replies
Stephen Bluck

Managing Tag Naming Variables in TypeScript

What is the preferred way to manage tag naming variables?
export class UserNotFound extends Data.TaggedError("UserNotFound")<{ email: S.EmailAddress }> {}

This string "UserNotFound" bothers me because it means I have things like this also duplicating the string literal:
Effect.catchTag("UserNotFound", () => ... ),

I can easily pull it out in a variable like:
export const UserNotFoundId = "UserNotFound";
export class UserNotFound extends Data.TaggedError(UserNotFoundId) {}

But I am sure you guys/gals have better patterns? I guess I could also attach it as a static method on the UserNotFound class itself...
Was this page helpful?