ds300 / react-native-typescript-transformer

Seamlessly use TypeScript with React Native
MIT License
657 stars 55 forks source link

How to enable decorators support? #94

Closed alexmbp closed 5 years ago

alexmbp commented 5 years ago

I use react-native-typescript-transformer because I need fully working decorators to use with my DI library (https://github.com/inversify/InversifyJS)

I have reflect-metadata installed and transformer is working, but looks like decorators metadata lost somewhere.

My tsconfig

{
  "compilerOptions": {
    "target": "es2015",
    "module": "commonjs",
    "lib": ["es6"],
    "jsx": "react",
    "sourceMap": true,
    "noEmit": true,
    "importHelpers": true,
    "strict": true,
    "strictPropertyInitialization": false,
    "moduleResolution": "node",
    "types": ["reflect-metadata"],
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "exclude": ["node_modules"]
}

Additionally I see, that TS part works ok

import * as tslib_1 from "tslib";
import { injectable } from 'inversify';
let TestInjection = class TestInjection {
    constructor() {
        console.warn('TestInjection instance created');
    }
    sayHello() {
        console.warn('Hello!');
    }
};
TestInjection = tslib_1.__decorate([
    injectable(),
    tslib_1.__metadata("design:paramtypes", [])
], TestInjection);
export default TestInjection;
//# sourceMappingURL=TestInjection.js.map
ds300 commented 5 years ago

Did you add it in tsconfig.json?

On Fri, 19 Apr 2019, 13:37 Oleksandr Didovych, notifications@github.com wrote:

I use react-native-typescript-transformer because I need fully working decorators to use with my DI library ( https://github.com/inversify/InversifyJS)

I have reflect-metadata installed and transformer is working, but looks like decorators metadata lost somewhere.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ds300/react-native-typescript-transformer/issues/94, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJPLKPLWIYEFUXX2IP6YQ3PRG4HVANCNFSM4HHD36VQ .

alexmbp commented 5 years ago

@ds300 Yes. I did. Generally I've found an issue. Issue was with code itself. I was thinking about babel/transformer, because where trying to make decorators working with babel plugins for proposal decorators, but caught an issues with property decorators. Everything is good with transformer. Thank you!

Roaders commented 4 years ago

@alexmbp did you get this working? I am having similar issues getting Ivversify working with React. Do you have an example repo where you manage to get this working? Thanks

sjerratsch commented 3 years ago

@Roaders This package solved it for me. Babel removes the metadata from "reflect-metadata". Not sure if this exactly fits your problem, but maybe someone will find this link helpful: https://www.npmjs.com/package/babel-plugin-transform-typescript-metadata