Skip to content

Matching on custom type #94

Answered by darrylnoakes
TheBroach asked this question in Q&A
Discussion options

You must be logged in to vote

After adding some formatting to your code, and then some filler types, this what I have:

type FetchBaseQueryError = unknown;
type SerializedError = unknown;
type ToolsLambdaError = unknown;

export type MyError = {
  id: string;
  statusCode: number;
  title: string;
  detail: string;
};

export type RTKQueryError =
  | Exclude<FetchBaseQueryError, { status: number; data: unknown }>
  | { status: number; data: { message: string | MyError } };

export const setErrorInfoByPattern = (error: RTKQueryError | SerializedError) =>
  match(error).with({ data: { message: ToolsLambdaError } });

The problem here, reported by TypeScript, is "'ToolsLambdaError' only refers to a type, but is being used …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@eboody
Comment options

Answer selected by gvergnaud
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants