fix(types): allow global.Netlify declaration merging
#494
+7
−7
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.
This fixes a TypeScript error that occurs when both
@netlify/[email protected]and@netlify/functionsare installed in a project (withskipLibCheck: false).It would fail with:
See for example #489.
You might think it wouldn't be valid to use both those packages at once, but TypeScript global module augmentation is truly global - it doesn't care where you import a package that performs global module augmentation; your whole TS project is compiled/typechecked as one program, unless you explicitly configure things completely separately for your
./netlify/functionsvs../netlify/edge-functionsvs.src/... which pretty much no one does.TypeScript allows multiple
vardeclarations in a scope to merge, butconstdeclarations are cannot be redeclared. When both packages declareglobal.Netlify, they must both usevarfor the declarations to merge successfully.We were actually already doing this correctly, but unfortunately there was a comment (copypasta from here, where it was accurate) that was lying about why (and there was no type test covering this). This led me to change it to
constin #434.I went down a rabbit hole trying to add a regression type test for this but I had to cut my losses after running into some issues. 😢