Open hminhman opened 9 months ago
@hminhman, thank you for the report. Can you post the actual typescript error thrown? I've noticed a few typing errors appearing and disappearing the past versions of Elysia, so I'm hoping to pinpoint the exact cause.
Hi @eelkevdbos ,
When I use: (it's ok with old elysia or add my above comment)
.use(i18next({initOptions: {lng: LANGUAGE.en, ...language}}))
then access t:
.post('/login', async function login({body, jwt, t}) { }
I face this error:
The reason in my opinion is: new elysia (>0.8.8) update their generic type. They added "derive, resolve" and more field in their "Decorators" so elysia-i18next out of date here:
{
request: {
i18n: i18n;
t: import("i18next").TFunction<[
"translation",
...string[]
], undefined>;
};
store: {};
// MISSING derive and resolve
}
My solution:
// My fix (has a comment about "translation" too)
export declare const i18next: (userOptions: Partial<I18NextPluginOptions>) => Elysia<"", {
request: {
i18n: i18n;
t: import("i18next").TFunction<[
"translation", // SHOULD CHANGE: I think this should be DefaultNamespace from i18next, because in some case, devs want to custom their namespace
...string[]
], undefined>;
};
store: {};
derive: {}; // ADD THIS
resolve: {}; // AND THIS
}, {
type: {};
error: {};
}, {}, {}, {}, false>; // ADD a missing empty object here too
Thank you.
Related versions:
After using Elysia 0.8.8, the type of t in request param always error. I tried to upgrade all (ts, i18next,...) but can't fix it. And finally I found that the new elysia has defined this
I try to edit directly
dist/index.d.ts
by adding enough Decorators and RouteBase then issue has gone.p/s: This is a good and helpful lib. Thanks for your support.