Skip to content
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

Is this needed anymore? #86

Open
henrikra opened this issue Oct 31, 2018 · 19 comments
Open

Is this needed anymore? #86

henrikra opened this issue Oct 31, 2018 · 19 comments

Comments

@henrikra
Copy link

I was just thinking is this library needed anymore since you can use Babel 7 to compile TypeScript 🤔

@aMarCruz
Copy link

aMarCruz commented Nov 1, 2018

For me, yes. Babel does not supports const enum, something that I use too much.
(Also, does not supports namespaces, but I don't use these).

@chawax
Copy link

chawax commented Nov 13, 2018

I agree we still need this library because of problems with Babel 7 (namespaces, enums, generated code not compatible with the default Android JSC, ...). But how do you configure Metro to still use react-native-typescript-transformer instead of Babel 7 in a React Native 0.57 project ?

@aMarCruz
Copy link

@chawax , my rn-cli.config.js :

/* eslint-env node */
module.exports = {
  transformer: {
    babelTransformerPath: require.resolve('react-native-typescript-transformer'),
  },
}

@chawax
Copy link

chawax commented Nov 13, 2018

Thanks, I will give it a try when I'll be at work tomorrow !

@chawax
Copy link

chawax commented Nov 14, 2018

It works ! You saved my life 👍 I was thinking about giving up Typescript in my React Native project because of this !

@fantasy525
Copy link

It works ! You saved my life 👍 I was thinking about giving up Typescript in my React Native project because of this !

my rn-cli.config.js:

module.exports = {
	getTransformModulePath() {
		return require.resolve('react-native-typescript-transformer');
	},
	getSourceExts() {
		return ['ts', 'tsx','d.ts'];
	},
};

@chawax
Copy link

chawax commented Nov 14, 2018

@fantasy525 Your solution will not work with React Native 0.57.4 if you use enums or namespaces because the Babel 7 Typescript transformer will be used.

@fantasy525
Copy link

@fantasy525 Your solution will not work with React Native 0.57.4 if you use enums or namespaces because the Babel 7 Typescript transformer will be used.

so this can work with rn 0.57.4?

/* eslint-env node */
module.exports = {
  transformer: {
    babelTransformerPath: require.resolve('react-native-typescript-transformer'),
  },
}

@chawax
Copy link

chawax commented Nov 14, 2018

Yes, exactly 👍

@tonyxiao
Copy link

Babel7's typescript also does not support emitting decorator metadata - disabling a lot of decorator based typescript libraries such as TypeDI and TypeORM.

Also, we really need to update the docs to fix this - just spent 2 hours debugging metro-loader before finally deducing this was the solution also.

@fantasy525
Copy link

Yes, exactly 👍

Hi,I find this configuration can work at rn 0.57.5

module.exports = {
    getTransformModulePath() {
        return require.resolve('react-native-typescript-transformer');
    },
    getSourceExts() {
        return ['ts', 'tsx'];
    }
}
// package.json
  "dependencies": {
    "react": "16.6.1",
    "react-native": "0.57.5",
    "tslib": "^1.9.3"
  },

@henrikra
Copy link
Author

@chawax Hey you said that the compiled TS code with babel is not working on React Native Android? Can you send link to this issue because I havent heard of it 🤔 ?

@chawax
Copy link

chawax commented Dec 17, 2018

Here is a link on the bug I encountered : facebook/react-native#21074

It looks like TS code compiled with Babel is not compatible with some Android versions (< 5.0) and also with iOS 9.3.

@henrikra
Copy link
Author

So you are saying that if I want to support Android < 5.0 and iOS <= 9.3 then I still have to use react-native-typescript-transformer to compile my code? But if I don't support these OS versions then I can use babel to do the transforming? :)

@afshin-hoseini
Copy link

@aMarCruz One day I'll travel to Mexico and invite you for 🍺
You saved my 4 days of confusing...

@chawax
Copy link

chawax commented Dec 18, 2018

@henrikra Well it probably depends on your project. The problem might come from a library I include in my project or from the Typescript code I generated from Swagger. If it is not the case for your project, Babel 7 TS compilation may work. Just give it a try on a Android 4.4 emulator for example ;)

@afshin-hoseini
Copy link

I would appreciate if you update the readme.
@ds300

@ds300
Copy link
Owner

ds300 commented Dec 18, 2018

I updated the readme

@fantasy525
Copy link

I think it is very necessary,the typescript compiler knows typescript better than Babel,I'll keep using this until Babel converts typescript with fewer problems,thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants