Closed nico1510 closed 5 years ago
I'm also interested in knowing about the compatibility of the soon to be released 0.57 version.
At least the v0.57 has changes to the Metro bundler config. I'm not really sure what changes are needed though.
Since the version 0.43.3, Metro has native support for Typescript by Babel 7.0.0 Plugin. See Add TypeScript support to React Native and #209 The react-native 0.57-rc3 comes with Metro 0.43.6 I don't know how it can afect this package.
You're correct typescript is now supported out of the box in react-native. I had to change my code to
interface SectionProps {
content: ((props: { i: number, isActive: boolean }) => React.ReactElement<any>) | string;
label: string;
info: string | number;
direction?: 'row' | 'column';
}
to make the babel typescript compiler accept it. I'm going to leave this issue open since metro is not even trying to make use of this transformer anymore but feel free to close it if you think it's not worth looking into now that typescript is supported by babel.
Could you add some notice to the README that it's not needed anymore in 0.57? (Which is awesome for react-native, but sad for this transformer :-( )
Yup, Typescript is supported by default in 0.57. No transformers needed.
@kristerkari thanks.
I went through a long way and finally found that it is actually as simple as this:
@xufeipyxis React Native should be able to pick up .ts
and .tsx
files automatically, and transpile them using Babel.(But keep the root entry file as 'index.js')
@xufeipyxis I updated one of my project that was using this library to React Native 0.57. I removed transformer and the project continued working normally. So I guess that you only need to install Typescript.
Here are my changes when updating to 0.57: https://github.com/kristerkari/react-native-css-modules-with-typescript-example/commit/d4ec640b374200011f9a3f5f3f462f2b0b58ac53#diff-c2e7e130f67fd2d0a2fe543cc954a128
For people that still want to use this module, solution is simple. In file rn-cli.config.js
remove keys getTransformModulePath
and getSourceExts
, and add section:
transformer: {
babelTransformerPath: require.resolve('react-native-typescript-transformer'),
},
For documentation, see https://facebook.github.io/metro/docs/en/configuration
thanks @vovkasm I think this can be closed
Man, I'm new to react-native. I just started trying to figure out why react native was being so strange wrt to typescript and this finally explains everything. The existing guides out there are all wrong right now.
@vovkasm thanks! I prefer the support for const enum
than the marginal gain in speed.
I'm aware that I'm a bit early here but I just wanted to let you know or ask if the transformer might be broken in the newest version of react-native ?
I'm getting this error which lets me think that babel is trying to transform the code before the typescript transformer jumps in.