You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportconstexample=newElysia().derive({as: "scoped"},async()=>{return{myProp: 42};}).macro(({ onBeforeHandle })=>({public: (_?: boolean)=>{onBeforeHandle(ctx=>{ctx.myProp;// myProp is number | undefined, but it is always undefined in runtime});},}));
What is the expected behavior?
We should be able to access derived props in the same scope.
What do you see instead?
Props are typed as maybe undefined and are all undefined during runtime.
Additional information
No response
The text was updated successfully, but these errors were encountered:
This happens because of the scoping mechanism. macro is global and applies to all routes while derive is defined for a subset of routes.
This means derive properties apply to self and parent, but not a scope beyond that in contrast to a global macro.
On the scope beyond the parent scope, myProp will be undefined while in self and parent is not.
Macro is public and can apply to any route so macro has to consider both scenarios, both myProp with value (in scope) and not (goes beyond scope).
In this code, myProp will be undefined because it goes out of (parent) scope.
However, if you set derive scope to global, myProp would not be undefined because derive is applied globally on the same scope as macro.
Setting derive as scoped:
Setting derive as global:
So the current behavior is correct because myProp could be either 42 or undefined because derive is defined as scope or local.
I'm closing the issue because this is not a bug but an intended feature to help developers catch bugs but feel free to continue the discussion if something is not clear or if you have more questions.
What version of Elysia.JS is running?
1.0.5
What platform is your computer?
Darwin 23.2.0 x86_64 i386
What steps can reproduce the bug?
What is the expected behavior?
We should be able to access derived props in the same scope.
What do you see instead?
Props are typed as maybe undefined and are all undefined during runtime.
Additional information
No response
The text was updated successfully, but these errors were encountered: