expo / web-examples

Examples of using Expo in the browser.
272 stars 51 forks source link

TypeScript support #23

Closed petrbela closed 5 years ago

petrbela commented 5 years ago

Is there any special setup for TypeScript? When I use a .ts file, webpack fails with Module not found: Error: Can't resolve ....

vstlouis commented 5 years ago

Same.. im trying to resolve this now. Any luck @petrbela ?

petrbela commented 5 years ago

I didn't have much time to dive into this so, for now, I'm running the TypeScript compiler separately "start": "tsc --watch | expo start", and have App.js point to the TypeScript build folder:

import App from './.build/App'
export default App

It messes up with source maps and it's not the ideal long-term solution but should be pretty easy to set up.

vstlouis commented 5 years ago

Got mine working.. heres the repo.

https://github.com/Ambitian/expo-rnw-ts-starter

Seems like it supports TS out the box just need to modify the babel config. Hope this helps

petrbela commented 5 years ago

@vstlouis The repo you linked is not visible/existing?

vstlouis commented 5 years ago

Sorry.. try again

petrbela commented 5 years ago

Ha, looks like it has been fixed in expo-cli 2.15 :)

When I was trying with expo-cli 2.14, I was getting this error:

ERROR in /frontend/expo-rnw-ts-starter/node_modules/expo/AppEntry.js
Module not found: Error: [CaseSensitivePathsPlugin] `/frontend/expo-rnw-ts-starter/App.json` does not match the corresponding path on disk `app.json`.
 @ /frontend/expo-rnw-ts-starter/node_modules/expo/AppEntry.js 2:0-28 8:22-25
 @ multi /Users/petrbela/.nvm/versions/node/v8.15.0/lib/node_modules/expo-cli/node_modules/react-dev-utils/webpackHotDevClient.js /frontend/expo-rnw-ts-starter/node_modules/expo/AppEntry.js

Btw you no longer need to run tsc separately. Just expo start, the @babel/typescript takes care of TS compilation.

vstlouis commented 5 years ago

Sweet, thanks!

petrbela commented 5 years ago

Actually, it seems @babel/typescript isn't necessary either.

Which means that TypeScript is now supported out of the box. Just make sure you're running the latest expo-cli, or the latest @expo/webpack-config if you're extending webpack config.

vstlouis commented 5 years ago

Mind throwing up a sample? Im running into a ton off errors without it?

petrbela commented 5 years ago

Just take the example at https://github.com/expo/web-examples/tree/master/expo-managed-workflow and rename App.js to App.tsx.