-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
TypeScript: Action-annotated method is undefined #1790
Comments
I fixed this by switching the compilation target to "es5". Haven't looked into the underlying problem. |
If I target ES5, won't I lose the benefits of proxies? |
@jbreckmckye no, target just specifies which language features are used, not which standard library is used |
It's still not working for me unfortunately. Also - I can't get class members decorated with For example, if I instantiate the class -
When I inspect the object, the This is using the TSC options |
Oh - one thing, I am using Parcel's |
Are you (or parcel) using babel? If so, what is it's configuration? It
seems like decorators are not applied at all?
Op di 6 nov. 2018 om 16:55 schreef Jimmy Breck-McKye <
notifications@github.com>:
… Oh - one thing, I am using Parcel's --target electron flag, which (as I
understand it) means the bundle won't contain any of its dependencies -
they'll get imported at runtime instead. Could this affect anything?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#1790 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhLDwnf0CciWuhfXMEHW13GdF_wFIks5usbD2gaJpZM4X8eEf>
.
|
Hi Michael - thanks for being so patient. So - this is going to sound rather strange, but I think I've found the issue, and it's something to do with my tsconfig setup, with multiple config files. I originally had three tsconfig files - one root, one for the main thread and one for the renderer, as below:
The TypeScript documentation suggests that this should work just fine; all the compilerOptions will be merged for each compile target. This would output class code that looked a little like this: function () {
function SomeClass(imagery, record) {
...
}
Project.prototype.doAThing = function () {
console.log('this is an action');
};
__decorate([mobx_1.action], Project.prototype, "doAThing");
return Project;
}(); Calling When I join the tsconfigs, however, things look subtly different. The proper class syntax is used and the
Now, both It's not clear to me exactly why my previous setup was mangling the compile output. Either the compilerOptions aren't really being merged properly or something strange is happening under the covers of In either case, it seems I solve the issue fairly easily by using a single I'm not sure if there's a clear takeaway or explanation as to what can go wrong with multiple tsconfigs, but at least I now know they have some pitfalls. Thanks for your patience on this. |
I'm experiencing this issue too. I'm using MobX with TypeScript and Next.js. import { observable } from 'mobx';
class UserStore {
@observable name = "Jon";
}
const store = new UserStore();
console.log(store.name); // undefined Unfortunately changing the target to |
Sounds like a bug that could be filed at TypeScript?
Op za 8 dec. 2018 om 11:10 schreef Jon Lambert <notifications@github.com>:
… I'm experiencing this issue in my project too. I'm using MobX with
Next.js, and @action or @observable decorated attributes are undefined.
Having to unify the tsconfig.json file seems like an unusual solution,
especially as I only have one. Does anybody have any idea why this might be
happening?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#1790 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhFc6MyyPXeZ8a4ZHMW_DzktJRHmyks5u24_4gaJpZM4X8eEf>
.
|
For those finding this issue later I managed to solve it by ensuring {
"presets": ["next/babel", "@zeit/next-typescript/babel"],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
"transform-class-properties",
]
}
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions. |
I'm having a strange issue with the MobX annotations, where an
@action
method doesn't exist on the resultant object. I'm not sure if the issue is with MobX, TypeScript / TSC, Parcel, or something else.If my class source is the following TypeScript:
And I invoke the method as follows:
I get an error:
Uncaught TypeError: car.selfDestruct is not a function
Evaluating
car.selfDestruct
in the console returnsundefined
.However, if I use the action function all seems fine:
Why can't I use the
@action
annotation?For reference, I am using MobX 5.5.2 with TypeScript 3.1.1. The compilation is being handled by ParcelJS 1.10.1. The target is an Electron app.
if it helps, here's my tsconfig:
The text was updated successfully, but these errors were encountered: