-
-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typing error when using onError
with derive
#653
Comments
My code looks like this: function fetchI18n(app: Elysia) {
return app.derive({ as: 'global' }, ({ headers }) => {
const header = headers[`x-minecraft-language`] || `en_us`;
const locales = getLocales(header);
return {
i18n: (path: string) => getPath(path, locales)
};
});
}
const elysia = new Elysia()
.use(fetchI18n)
.onError(({ code, set, error, i18n }) => {
if(code == 'VALIDATION') {
set.status = 422;
return { error: i18n(error.message) };
} else if(code == 'NOT_FOUND') {
set.status = 404;
return { error: i18n(`error.notFound`) };
} else {
set.status = 500;
Logger.error(error.message);
return { error: i18n(`error.unknownError`) };
}
})
.listen(config.port); I don't get any type errors and typescript also says that the function
|
@RappyTV |
@nxht |
Issue seems to be fixed in 1.1.3 (similar error with #722 I guess) |
What version of Elysia.JS is running?
1.0.21
What platform is your computer?
Linux 5.15.146.1-microsoft-standard-WSL2 x86_64 x86_64
What steps can reproduce the bug?
What is the expected behavior?
No type error as the code works well.
Type of
test
should be inferred asstring | undefined
or at leaststring
.Also, there was no type error when tested on elysia@1.0.20
What do you see instead?
Additional information
Same code on elysia@1.0.20
The text was updated successfully, but these errors were encountered: