react-native-typescript-transformer icon indicating copy to clipboard operation
react-native-typescript-transformer copied to clipboard

Is this needed anymore?

Open henrikra opened this issue 5 years ago • 19 comments

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

henrikra avatar Oct 31 '18 06:10 henrikra

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).

aMarCruz avatar Nov 01 '18 17:11 aMarCruz

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 avatar Nov 13 '18 21:11 chawax

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

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

aMarCruz avatar Nov 13 '18 21:11 aMarCruz

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

chawax avatar Nov 13 '18 21:11 chawax

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

chawax avatar Nov 14 '18 08:11 chawax

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 avatar Nov 14 '18 08:11 fantasy525

@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.

chawax avatar Nov 14 '18 08:11 chawax

@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'),
  },
}

fantasy525 avatar Nov 14 '18 08:11 fantasy525

Yes, exactly 👍

chawax avatar Nov 14 '18 09:11 chawax

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.

tonyxiao avatar Nov 18 '18 08:11 tonyxiao

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"
  },

fantasy525 avatar Nov 18 '18 11:11 fantasy525

@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 🤔 ?

henrikra avatar Dec 17 '18 19:12 henrikra

Here is a link on the bug I encountered : https://github.com/facebook/react-native/issues/21074

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

chawax avatar Dec 17 '18 21:12 chawax

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? :)

henrikra avatar Dec 18 '18 06:12 henrikra

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

afshin-hoseini avatar Dec 18 '18 07:12 afshin-hoseini

@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 ;)

chawax avatar Dec 18 '18 07:12 chawax

I would appreciate if you update the readme. @ds300

afshin-hoseini avatar Dec 18 '18 08:12 afshin-hoseini

I updated the readme

ds300 avatar Dec 18 '18 11:12 ds300

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!

fantasy525 avatar Jan 28 '19 13:01 fantasy525