-
Notifications
You must be signed in to change notification settings - Fork 634
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
Add TypeScript support to React Native #209
Conversation
CI error:
Not sure what this means 🤷♂️ Anyway I think that @CompuIves or @rafeca could provide some feedback on this. |
Yeah, looked at that as well, and inspecting that file I can only find one declaration of Won't have much more time during the day to look at this though... |
I have a commit that's going to land soon that fixes this error |
Codecov Report
@@ Coverage Diff @@
## master #209 +/- ##
==========================================
+ Coverage 85.46% 85.47% +<.01%
==========================================
Files 134 134
Lines 4390 4391 +1
Branches 676 677 +1
==========================================
+ Hits 3752 3753 +1
Misses 566 566
Partials 72 72
Continue to review full report at Codecov.
|
Yes, it's a bug in babel scope counting (more info) that causes an issue in our inline requires transformer. I've worked around the issue by disabling the inline requires plugin in our tests (that's fair because we don't use inline requires to transpile Metro) |
Awesome! I've rebased on I also changed the approach to be a bit simpler, now the only thing added is an override for I've opted to enable JSX in both |
If anyone is interested, the size of the two new dependencies are:
So adding TypeScript support to React Native will only add 4,949 bytes of extra download 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the contribution! I love how simple it's been to add native support for TypeScript 😃
Small note: since we don't use TypeScript internally at FB, we're not going to be able to fully maintain this feature, so I expect you/the community to help here in the future 😄
Something I recommend to do is to add a TypeScript file to the test bundle that we use for our end to end tests: this will prevent TypeScript support from breaking in the future.
@@ -124,6 +128,14 @@ const getPreset = (src, options) => { | |||
comments: false, | |||
compact: true, | |||
plugins: defaultPlugins.concat(extraPlugins), | |||
overrides: [ | |||
{ | |||
test: file => isTypeScriptSource(file || 'internal.js'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the fileName
param in isTypeScriptSource()
optional (and check if it's not null there)? This way we can avoid passing the internal.js
thingy 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing!
@rafeca Fixed your comment 👌 Some things, just because I'm new to this repo:
Please let me know if you prefer any other style/way of working |
Will absolutely maintain this! We are going to use this at work so will be able to this during work hours 👍
Absolutely 🙌
Thanks for the comments and quick responses ❤️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I amended my commit instead of pushing a new commit
👍
I used !! since I found that 10 times in the rest of the code, I only found Boolean(...) once
💯
I rebased on master again
🥇
var type = 'TypeScript'; | ||
exports.type = type; | ||
var test = true; | ||
exports.test = test; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!!! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rafeca is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Thank you for landing this 🚀 |
@rafeca would it be possible to cut a release, |
yes, I was planning to release |
Awesome 👏 thanks! |
Wow this is really great thanks a lot! I just added a note to the TypeScript template (https://github.com/emin93/react-native-template-typescript) that it will be supported out of the box in future React Native versions. 😄 |
Thanks! Love it! |
Summary
This PR adds support for TypeScript out-of-the-box. Existing codebases should work as before, but React Native should be able to pick up
.ts
and.tsx
files automatically, and transpile them using Babel.Note that no actual type-checking will be done, this is in line with how the current Flow support is working. The user can run
tsc --noEmit
to type-check the project.Test plan
I'm currently working on this. I haven't been able to figure out how to test these changes in a local RN application.
I'll be meeting up with @kelset today, hopefully he can help me with this 💌
With these changes, the following RN project should be able to work without further configuration: https://github.com/LinusU/react-native-babel-typescript-test