inversify / InversifyJS

A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
http://inversify.io/
MIT License
11.34k stars 719 forks source link

Add babel legacy decorators support #1050

Closed EugenePisotsky closed 1 month ago

EugenePisotsky commented 5 years ago

Inversify decorators don't work with Babel, maybe because of different specification:

Possible Solution

Here's an example of working with Babel decorator, I suppose it works because it returns the descriptor (assign doesn't work):

function lazyInject(identifier?) {
    return (protoOrDescriptor, name?): any => ({
        configurable: true,
        enumerable: true,
        get: () => {
            return container.get(identifier);
        },
        set: () => void 0,
    });
}

Context

React Native 0.59 updated their bundler version and now it doesn't support the latest react-native-typescript-transformer. The problem is that developers of react-native-typescript-transformer are not going to keep supporting it and also recommend developers switching to Babel. Now it's impossible to use InversifyJS with ReactNative since 0.59 at all, as Babel is the only option we can use.

shatodj commented 5 years ago

Check this out

1007

mtfranchetto commented 4 years ago

Is there an update on this topic? I'm facing the same issue right know with a RN application and I don't know how to workaround this problem even after following #1007. Is the only option to use Inversify without decorators? Like in vanilla JS

jonatanlins commented 2 years ago

This worked for me: https://github.com/inversify/InversifyJS/issues/1007#issuecomment-490835213

MehediEhteshum commented 5 months ago

In my project, I had issues caused by babel and inversify @inject directive usage. I used Metro server (not Expo). I believe the solution must be similar for both. I couldn't find a standalone solution. After much trial and error, I solved it. I hope my solution will save someone a lot of time.

You can find my detailed answer here >> https://stackoverflow.com/a/78696852/13607767

notaphplover commented 1 month ago

Hey all, I undestand your concerns here. Given the existence of babel-plugin-transform-typescript-metadata I don't think we don't need to provide babel decorators.

I'm closing the issue beliving the amount of different workarounds and this StackOverflow answer relying on the babel plugin are more than enough.

Feel free to comment on this issue if you think there's something left.