React-native-paper: Enforce import type for type imports

Created on 17 Jun 2020  ยท  9Comments  ยท  Source: callstack/react-native-paper

For the next major, we should enforce using the new import type feature of TypeScript to import types everywhere. This will let babel drop import statements when only types are used from a file and result in smaller file size/better tree shaking.

To do this, we can add "importsNotUsedAsValues": "error" in the tsconfig.json and then fix all of the type errors (it'd be just changing import to import type).

good first task

Most helpful comment

@BatDroid try updating @babel/core and metro-react-native-babel-preset as well, and if it doesn't work, try deleting yarn.lock entirely.

All 9 comments

Can i work on this please?

Feel free

@satya164
I worked on it but here is what happened.
As you can see here import type is not supported in until version 2.* of prettier.
The project's prettier version was 1.19.0 so I updated to the latest version and the errors related to import type were gone, but there were bunch of other errors like this that there were no options to be included in .prettierrc for preventing the error.
I believe we(I) have to migrate the whole project to prettier with --fix command and then refactor the "importsNotUsedAsValues": "error". Is it ok if make this refactor first or you have other solutions?

Yeah, let's make those changes

Also make sure to send the PR to 4.0 branch :)

@BatDroid How is it going? Do you need any help with the PR? Maybe someone from paper core team can help you cause ideally, we need this to be merged this week.

@Trancever Im working on it at the moment. I have applied all the changes but I received test fails from Jest for not recognizing the import type.
I updated the jest to the latest version in the project and those test fails were all gone. However, there are errors (that seems to be like warnings) and more important one of the tests is failing in BottomNavigation.test.js. the error is this :

 FAIL  src/components/__tests__/BottomNavigation.test.js
  โ— Test suite failed to run

    Call retries were exceeded

      at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:191:21)

I'm gonna keep working on it for a few hours to see if I can resolve it. meanwhile, you can either wait or if you have the solution would appreciate to share :)

@BatDroid try updating @babel/core and metro-react-native-babel-preset as well, and if it doesn't work, try deleting yarn.lock entirely.

Fixed on 4.0 branch

Was this page helpful?
0 / 5 - 0 ratings

Related issues

scottybo picture scottybo  ยท  3Comments

timothystewart6 picture timothystewart6  ยท  4Comments

zxccvvv picture zxccvvv  ยท  4Comments

talaikis picture talaikis  ยท  3Comments

sm2017 picture sm2017  ยท  4Comments