-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Avoid __DEV__
declaration conflict with React Native (when "skipLibCheck": false
in tsconfig.json
)
#9386
Merged
benjamn
merged 3 commits into
release-3.6
from
issue-9039-prevent-__DEV__-conflict-with-React-Native
Feb 9, 2022
Merged
Avoid __DEV__
declaration conflict with React Native (when "skipLibCheck": false
in tsconfig.json
)
#9386
benjamn
merged 3 commits into
release-3.6
from
issue-9039-prevent-__DEV__-conflict-with-React-Native
Feb 9, 2022
Conversation
This file contains 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
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment explains the situation in a bit more detail.
benjamn
added
⏮ compatibility
backwards compatibility-related issues and PRs
⚛️ React-related
⛑ TypeScript
🌤 has-workaround
👩🔬 needs-more-tests
🛠 tooling
🥚 backwards-compatible
for PRs that do not introduce any breaking changes
🧞♂️ enhancement
🧩 implementation-detail
labels
Feb 2, 2022
This was referenced Feb 2, 2022
benjamn
force-pushed
the
issue-9039-prevent-__DEV__-conflict-with-React-Native
branch
from
February 4, 2022 01:11
5d83908
to
8627b19
Compare
benjamn
deleted the
issue-9039-prevent-__DEV__-conflict-with-React-Native
branch
February 9, 2022 17:21
benjamn
added a commit
that referenced
this pull request
Feb 15, 2022
benjamn
added a commit
that referenced
this pull request
Feb 15, 2022
These changes are now available from npm in |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
🥚 backwards-compatible
for PRs that do not introduce any breaking changes
⏮ compatibility
backwards compatibility-related issues and PRs
🧞♂️ enhancement
🌤 has-workaround
🧩 implementation-detail
👩🔬 needs-more-tests
⚛️ React-related
🛠 tooling
⛑ TypeScript
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/client
with"skipLibCheck": false
in theirtsconfig.json
files. Before this PR, the only workaround for issue #9039 was to set"skipLibCheck": true
to avoid rechecking.d.ts
files 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/client
does 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.