nx-react-native icon indicating copy to clipboard operation
nx-react-native copied to clipboard

Typescript type checking

Open ceremonious opened this issue 5 years ago • 4 comments

Is there a way for me to view all of the type errors in a NX React Native app? When running the React app or the Node app, NX automatically runs the type checker when running nx serve, but it doesn't do the same when running nx start for my React Native app.

Do I need to use tsc? What's the proper configuration for that?

ceremonious avatar Dec 17 '20 11:12 ceremonious

We rely on the metro bundler and the corresponding babel metro preset to transpile TypeScript. There might be a way to tweak it to not do transpile only, but also type check.

Need to look into it.

jaysoo avatar Dec 17 '20 19:12 jaysoo

Need to give this one some thought, the best way to do typechecking currently is to run tsc.

You can add a tsc target to your app:

npx nx g @nrwl/workspace:run-commands \
typecheck \
--command="tsc" \
--project=my-app \
--cwd=apps/my-app

Then you can run npx nx typecheck my-app during CI, and rely on your IDE (VSCode or IntelliJ to check locally).


There are some issues making it hard to get tsc to work fully with React Native. For example, it cannot resolve platform specific files like foo.android.tsx vs foo.ios.tsx so it wouldn't be good to force typechecks everywhere just yet.

Related issue: https://github.com/microsoft/TypeScript/issues/21926

jaysoo avatar Dec 21 '20 19:12 jaysoo

Just a quick update, we are still looking into this but we have a few higher priority items in the works right now (including moving this repo back into the main Nx monorepo).

jaysoo avatar Jan 11 '21 18:01 jaysoo

I'm doing the above and running tsc through @nrwl/workspace:run-commands (thanks for the suggestion!), but:

  • A) not sure what is the right way to use tsc with the tsconfig.app.json and tsconfig.spec.json setup. If I do tsc -b tsconfig.json, any type errors show up twice.
  • B) run-commands removes the formatting from the output of tsc, so it's a lot less legible than running tsc directly

Appreciate if you have any advice :)

raymondji avatar Nov 19 '21 09:11 raymondji