InversifyJS icon indicating copy to clipboard operation
InversifyJS copied to clipboard

Add babel legacy decorators support

Open EugenePisotsky opened this issue 6 years ago • 4 comments

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.

EugenePisotsky avatar Feb 19 '19 21:02 EugenePisotsky

Check this out #1007

shatodj avatar May 13 '19 14:05 shatodj

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

mtfranchetto avatar Jan 13 '20 10:01 mtfranchetto

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

jonatanlins avatar Mar 19 '22 20:03 jonatanlins