Description
What version of Elysia.JS is running?
1.0.13
What platform is your computer?
x64
What steps can reproduce the bug?
const app = new Elysia()
.derive({ as: 'global' }, () => ({ hello: 'world' }))
.onError(({ hello }) => `404: ${hello}`)
.get('/', ({ hello }) => `Root: ${hello}`)
.listen(3000)
What is the expected behavior?
/
rendersRoot: world
/will-404
renders404: world
OR
the.onError
handler does not typecheck
What do you see instead?
/
rendersRoot: world
/will-404
renders404: undefined
Additional information
This seems to happen only when using { as: 'global' }
. With 'scoped'
/'local
(or omitting) hello
is not typed in onError
(but is properly typed in e.g. handlers).
Not sure if it's the type or the runtime behavior that's wrong, but it felt natural to me to write it this way -- in particular I need to access my derived isAuthorized
in onError
when NOT_FOUND
to avoid leaking my app structure to unauthorized users.
In my particular case { as: 'global' }
is needed because I want to inject this isAuthorized
globally from a plugin.
If onError
(on router) isn't meant to access the derive
d properties (which might be the case according to the lifecycle graph, since derive
happens on Transform Hook
while NOT_FOUND
I assume comes from Router
), what's the alternative approach here, if any?