Is this needed anymore?
henrikra opened this issue ยท 19 comments
I was just thinking is this library needed anymore since you can use Babel 7 to compile TypeScript ๐ค
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).
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 ?
@chawax , my rn-cli.config.js :
/* eslint-env node */
module.exports = {
transformer: {
babelTransformerPath: require.resolve('react-native-typescript-transformer'),
},
}
Thanks, I will give it a try when I'll be at work tomorrow !
It works ! You saved my life ๐ I was thinking about giving up Typescript in my React Native project because of this !
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'];
},
};
@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 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'),
},
}
Yes, exactly ๐
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.
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"
},
@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 ๐ค ?
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.
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? :)
@aMarCruz One day I'll travel to Mexico and invite you for ๐บ
You saved my 4 days of confusing...
@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 ;)
I would appreciate if you update the readme.
@ds300
I updated the readme
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!