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
The context passed by the decorator looks like this: {"kind":"field","name":"addFiles","static":false,"private":false,"metadata":{},"access":{}} Versions
I think this issue is not visible when using babel because babel does support addInitializer (in conflict with the spec). But it does appear when compiling with swc (which follows the spec)
The text was updated successfully, but these errors were encountered:
@phiresky The spec has been revised - addinitializer was added to field decorators for consistency, but, yeah, it looks like the README in the GitHub repo has not been updated to reflect (looks like it hasn't been updated for 3 years, but revisions have been made to the spec since).
I'm not super familiar with SWC, but high-level it re-implements Typescript's transpiler, yeah? Otherwise, I would think that maybe update TS, but I don't think that's applicable.
I have no authority of the repo here, so I'll let someone else weigh-in more officially, but my thought would be to look for/post an issue with SWC (if all versions there are current) and use patch-package (to tweak MobX away from addInitializer) in the meantime.
Intended outcome:
@action decorators should work with fields (lambdas).
Actual outcome:
It throws
addInitializer
is not a function. The reason is this code:mobx/packages/mobx/src/types/actionannotation.ts
Lines 70 to 78 in df7e1eb
How to reproduce the issue:
@action foo = () => {};
The context passed by the decorator looks like this:
{"kind":"field","name":"addFiles","static":false,"private":false,"metadata":{},"access":{}}
Versions
Spec reference
If you look at the class field spec, it says this: https://github.com/tc39/proposal-decorators#class-fields
The interface of the decorator looks like this:
So probably instead of using addInitializer the initializer should be returned.
cc @Matchlighter
I think this issue is not visible when using babel because babel does support addInitializer (in conflict with the spec). But it does appear when compiling with
swc
(which follows the spec)The text was updated successfully, but these errors were encountered: