Avoid __DEV__ declaration conflict with React Native (when "skipLibCheck": false in tsconfig.json)#9386
Merged
benjamn merged 3 commits intorelease-3.6from Feb 9, 2022
Conversation
benjamn
commented
Feb 2, 2022
Comment on lines
3
to
20
| declare global { | ||
| // Despite our attempts to reuse the React Native __DEV__ constant instead of | ||
| // inventing something new and Apollo-specific, declaring a useful type for | ||
| // __DEV__ unfortunately conflicts (TS2451) with the global declaration in | ||
| // @types/react-native/index.d.ts. | ||
| // | ||
| // To hide that harmless conflict, we @ts-ignore this line, which should | ||
| // continue to provide a type for __DEV__ elsewhere in the Apollo Client | ||
| // codebase, even when @types/react-native is not in use. | ||
| // | ||
| // However, because TypeScript drops @ts-ignore comments when generating .d.ts | ||
| // files (https://github.com/microsoft/TypeScript/issues/38628), we also | ||
| // sanitize the dist/utilities/globals/global.d.ts file to avoid declaring | ||
| // __DEV__ globally altogether when @apollo/client is installed in the | ||
| // node_modules directory of an application. | ||
| // | ||
| // @ts-ignore | ||
| const __DEV__: boolean | undefined; |
Member
Author
There was a problem hiding this comment.
This comment explains the situation in a bit more detail.
This was referenced Feb 2, 2022
5d83908 to
8627b19
Compare
benjamn
added a commit
that referenced
this pull request
Feb 15, 2022
benjamn
added a commit
that referenced
this pull request
Feb 15, 2022
Member
Author
|
These changes are now available from npm in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Should fix #9039, by avoiding shipping any global declaration of the
__DEV__constant (introduced in #8347).This change allows React Native applications to use
@apollo/clientwith"skipLibCheck": falsein theirtsconfig.jsonfiles. Before this PR, the only workaround for issue #9039 was to set"skipLibCheck": trueto avoid rechecking.d.tsfiles withinnode_modules/@apollo/client/.If you need a
__DEV__declaration in your application code, either use@types/react-native(which declares__DEV__globally) or declare it yourself, in your application:Since merely using
@apollo/clientdoes not guarantee__DEV__will be defined outside the library (for example, no__DEV__polyfill is necessary when build tools strip/replace__DEV__at build time), I think it makes sense to avoid advertising a type for__DEV__globally, even if there was no conflict to worry about.