diff --git a/README.md b/README.md index 16aa61a..71ad257 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,27 @@ import jQuery from 'jquery' // ... ``` +## Typescript + +The library includes automatic support providing the necessary type declarations for an integration without further configuration. + +```ts +import globalJsdom from "global-jsdom"; + +describe("Typescript test example", () => { + let cleanup: { (): void }; + + before(() => { + cleanup = globalJsdom(); + }); + + after(() => { + cleanup(); + }); + +}) +``` + ## Migration from `jsdom-global` 1. `browserify` support is dropped - I have no way to test this and `webpack` started giving higher priority to the `browser` field in `package.json` than `module` diff --git a/packages/global-jsdom/package.json b/packages/global-jsdom/package.json index fd0ad0d..e7dad43 100644 --- a/packages/global-jsdom/package.json +++ b/packages/global-jsdom/package.json @@ -20,9 +20,11 @@ }, "module": "./esm/index.mjs", "main": "./commonjs/index.cjs", + "types": "types/index.d.ts", "files": [ "commonjs/*", - "esm/*" + "esm/*", + "types/*" ], "bugs": { "url": "https://github.com/modosc/global-jsdom/issues" diff --git a/packages/global-jsdom/types/index.d.ts b/packages/global-jsdom/types/index.d.ts new file mode 100644 index 0000000..e242417 --- /dev/null +++ b/packages/global-jsdom/types/index.d.ts @@ -0,0 +1,7 @@ +declare module "global-jsdom" { + import { ConstructorOptions } from "jsdom"; + + function globalJsdom(html?: string, options?: ConstructorOptions): () => void; + + export = globalJsdom; +}