fix(events,fetch): avoid polluting global types #427
Merged
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.
Description
Sorry for going straight for a PR, I figured this fix was best described with code.
We're seeing issues with trying to use libraries that both declare global symbols such as
_fetch
, in this case this library along withcross-fetch
. Due to these libraries both declaring this same global type, TypeScript will treat this as an error simply if both dependencies are installed in the same project. Using--skipLibCheck
is not an option as this is an important check that we want to keep.There are other solutions to this issue, but I figured the one I propose is the cleanest.
globalThis
has been available in TypeScript since 3.4, released 4 years ago.Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can
reproduce. Please also list any relevant details for your test configuration
yarn run ts:check
Install both
@whatwg-node/fetch
andcross-fetch
in the same projectRun
tsc
, with--skipLibCheck=false
. Multiple type errors are produced, for example:Replace the contents of
node_modules/@whatwg-node/fetch/dist/index.d.ts
in the project with the contents from this PR.Run
tsc
again, the errors are now gone and no new errors appear.I applied the same fix to
events
to keep things consistent, but have not tested it in the same way.Test Environment:
typescript
: 4.7.4Checklist:
CONTRIBUTING doc and the
style guidelines of this project