fix: correct a type error occurring when the `requestEvent.fail()` is returned in the `actionQrl` or `loaderQrl`
Overview
What is it?
- [ ] Feature / enhancement
- [ ] Bug
- [x] Docs / tests / types / typos
Description
routeAction$, globalAction$ and routeLoader$ have incorrect type when the requestEvent.fail(...) is returned in the actionQrl or loaderQrl.
ex:
export const useRouteActionWithFail = routeAction$((data, requestEvent) => {
if (Math.random() > 1) {
return requestEvent.fail(500, {
sad: 'sad',
errorMessage: 'why',
});
}
return {
happy: 'happy',
day: 'day',
};
});
Use cases and why
Actual

Expected behavior
The type errors should not appear.
To facilitate the reproduction of this bug, here is my testing code.
export const useRouteAction = routeAction$((data, requestEvent) => {
return {
happy: 'happy',
day: 'day',
};
});
export const useRouteActionWithFail = routeAction$((data, requestEvent) => {
if (Math.random() > 1) {
return requestEvent.fail(500, {
sad: 'sad',
errorMessage: 'why',
});
}
return {
happy: 'happy',
day: 'day',
};
});
export const useRouteActionWithFailWithValidation = routeAction$((data, requestEvent) => {
if (Math.random() > 1) {
return requestEvent.fail(500, {
sad: 'sad',
errorMessage: 'why',
});
}
return {
happy: 'happy',
day: 'day',
};
}, zod$({}));
export const useRouteLoader = routeLoader$((requestEvent) => {
return {
happy: 'happy',
day: 'day',
};
});
export const useRouteLoaderWithFail = routeLoader$((requestEvent) => {
if (Math.random() > 1) {
return requestEvent.fail(500, {
sad: 'sad',
errorMessage: 'why',
});
}
return {
happy: 'happy',
day: 'day',
};
});
export const useRouteLoaderWithFailWithValidation = routeLoader$((requestEvent) => {
if (Math.random() > 1) {
return requestEvent.fail(500, {
sad: 'sad',
errorMessage: 'why',
});
}
return {
happy: 'happy',
day: 'day',
};
}, zod$({}));
export default component$(() => {
const routeAction = useRouteAction();
routeAction.value?.happy;
routeAction.value?.day;
const routeActionWithFail = useRouteActionWithFail();
routeActionWithFail.value?.happy; // ❌ Property 'happy' does not exist on type 'FailReturn<...>'
routeActionWithFail.value?.day; // ❌ Property 'day' does not exist on type 'FailReturn<...>'
routeActionWithFail.value?.sad; // ❌ Property 'sad' does not exist on type 'FailReturn<...>'
routeActionWithFail.value?.errorMessage; // ❌ Property 'errorMessage' does not exist on type
const routeActionWithFailWithValidation = useRouteActionWithFailWithValidation();
routeActionWithFailWithValidation.value?.happy;
routeActionWithFailWithValidation.value?.day;
routeActionWithFailWithValidation.value?.sad;
routeActionWithFailWithValidation.value?.errorMessage;'FailReturn<...>'
const routeLoader = useRouteLoader();
routeLoader.value.happy;
routeLoader.value.day;
const routeLoaderWithFail = useRouteLoaderWithFail();
routeLoaderWithFail.value.happy; // ❌ Property 'happy' does not exist on type 'FailReturn<...>'
routeLoaderWithFail.value.day; // ❌ Property 'day' does not exist on type 'FailReturn<...>'
routeLoaderWithFail.value.sad; // ❌ Property 'sad' does not exist on type 'FailReturn<...>'
routeLoaderWithFail.value.errorMessage; // ❌ Property 'errorMessage' does not exist on type 'FailReturn<...>'
const routeLoaderWithFailValidation = useRouteLoaderWithFailWithValidation();
routeLoaderWithFailValidation.value.happy;
routeLoaderWithFailValidation.value.day;
routeLoaderWithFailValidation.value.sad;
routeLoaderWithFailValidation.value.errorMessage;
return <></>;
});
Checklist:
- [x] My code follows the developer guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation
- [ ] Added new tests to cover the fix / functionality
Run & review this pull request in StackBlitz Codeflow.
Are you still working on this or is it abandoned?
@gioboa Oh, I totally forget this PR. I am willing to work on it if the related issue is still open.
The issue is still open, please check if with the current release the issue is there too
@gioboa I found there are still some type errors for actions and loaders, I fixed the action type in this PR and I will try to fix loader type in later PR. So, I think this PR can be closed.
Thanks for investigating in it. 😊