Effect CommunityEC
Effect Community3y ago
4 replies
Stephen Bluck

Creating a `isRedirect` Typeguard for TaggedEnum

How do I make a isRedirect which uses a typeguard when using TaggedEnum:
export type ResponseError = Data.TaggedEnum<{
  INTERNAL_SERVER_ERROR: { message: string; status: 500 };
  BAD_REQUEST: { message: string; status: 400 };
  UNAUTHORISED: { message: string; status: 401 };
  NOT_FOUND: { message: string; status: 404 };
  REDIRECT: { location: string; status: 302 };
}>;
const ResponseError = Data.taggedEnum<ResponseError>();

const isRedirect = (error: ResponseError): error is ??? => error._tag === 'REDIRECT'
Was this page helpful?