redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

[Feature request] Make mutation return discriminated union

Open bn-piar opened this issue 3 years ago • 0 comments

Related to #1364

change typings from

{
    data: T;
} | {
    error: FetchBaseQueryError | SerializedError;
}

to

{
    data: T;
    error?: never;
} | {
    data?: never;
    error: FetchBaseQueryError | SerializedError;
}

It'd allow to conditionally operate on data returned by mutation.

const data = someMutation();
if (data.data) {
  // data's here, error's not
} else {
  // error's here, data's not
}

Didn't check implementation of generated hooks but I believe it won't be hard to implement discriminated unions.

Maybe good first issue?

bn-piar avatar Sep 29 '22 04:09 bn-piar