Skip to content

Fix compile errors with skip lib check #181

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

Merged
merged 1 commit into from
Feb 5, 2021
Merged

Fix compile errors with skip lib check #181

merged 1 commit into from
Feb 5, 2021

Conversation

sshquack
Copy link
Contributor

@sshquack sshquack commented Feb 5, 2021

Summary

Currently running the Typescript compiler on the template throws over 177 errors (See gist https://gist.github.com/sshquack/1e0d1425a10fbfa2b6eab91c8eeda235#file-rn-tsc-errors for full list of errors).

Root cause

All the errors are because tsc is finding duplicate types exposed in the node_modules. The fix is to skip the library check while doing type resolution per the compiler flag skipLibCheck https://www.typescriptlang.org/tsconfig#skipLibCheck

Before

$ yarn run tsc
node_modules/@types/react-test-renderer/node_modules/@types/react/index.d.ts(2982,14): error TS2300: Duplicate identifier 'LibraryManagedAttributes'.
node_modules/@types/react-test-renderer/node_modules/@types/react/index.d.ts(2995,13): error TS2717: Subsequent property declarations must have the same type.  Property 'a' must be of type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>', but here has type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>'.
node_modules/@types/react-test-renderer/node_modules/@types/react/index.d.ts(2996,13): error TS2717: Subsequent property declarations must have the same type.  Property 'abbr' must be of type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>', but here has type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>'.
...

Found 177 errors.

$ echo $?
1

After

$ yarn run tsc

$ echo $?
0

References

It looks like a bunch of folks have tripped over this issue according to StackOverflow. See https://stackoverflow.com/questions/54135918/typescript-and-react-native-hundreds-of-errors-from-node-modules-types-when-co

Verification

$ yarn run tsc ✔️
$ yarn run test ✔️

@emin93
Copy link
Member

emin93 commented Feb 5, 2021

Shouldn't the exclude take care of that?

@sshquack
Copy link
Contributor Author

sshquack commented Feb 5, 2021

@emin93 The exclude is to exclude sources and the skipLibCheck is to exclude from type resolution. They are both very different options.

This is also why skipLibCheck is set to true in the Create-React-App (CRA) TypeScript template as well.

So it would be good to keep this option the same as CRA and avoid surprises when invoking the tsc compiler.

Copy link
Member

@emin93 emin93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for the clarification 🙏

@emin93 emin93 merged commit 751c033 into react-native-community:master Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants