redux-toolkit
redux-toolkit copied to clipboard
[Feature request] Make mutation return discriminated union
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?