Fix global Cypress namespace augumentation#14
Merged
jm-mailosaur merged 2 commits intomailosaur:masterfrom Mar 17, 2021
miluoshi:master
Merged
Fix global Cypress namespace augumentation#14jm-mailosaur merged 2 commits intomailosaur:masterfrom miluoshi:master
jm-mailosaur merged 2 commits intomailosaur:masterfrom
miluoshi:master
Conversation
This is fixed with 2 things:
1. For global namespace augumentation to work correctly, the augumentation needs to be in an "ambient" context (vs module context).
You can achieve ambient context in d.ts files in 2 ways:
a.) by not using import/export keywords (using them toggles module context)
b.) by wrapping namespace augumentation in `declare global {}` block - ambient context is inside this block.
See more info here:
- https://www.typescriptlang.org/docs/handbook/release-notes/typescript-1-8.html#augmenting-globalmodule-scope-from-modules
- microsoft/TypeScript-Handbook#180 (comment)
2. For Typescript to be able to use provided type declarations, we need to point it to a correct d.ts file.
This is done by specifying path to this file in package.json's field "types".
With this, an application just needs to `import 'cypress-mailosaur'` and types just work
Closed
|
Just a suggestion en passant (I know it was like this before the PR): I've usually seen a package's definitions in a |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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 is fixed with 2 things:
You can achieve ambient context in d.ts files in 2 ways:
a.) by not using import/export keywords (using them toggles module context)
b.) by wrapping namespace augumentation in
declare global {}block - ambient context is inside this block.See more info here:
This is done by specifying path to this file in package.json's field "types".
With this, an application just needs to
import 'cypress-mailosaur'and types just workfixes #12