diff --git a/source/lib/config.ts b/source/lib/config.ts index d106b422..dc1a8718 100644 --- a/source/lib/config.ts +++ b/source/lib/config.ts @@ -34,7 +34,7 @@ export default (pkg: {tsd?: RawConfig}, cwd: string): Config => { compilerOptions: { strict: true, jsx: JsxEmit.React, - lib: ['lib.es2017.d.ts'], + lib: ['es2017', 'dom'], module: ModuleKind.CommonJS, target: ScriptTarget.ES2017, esModuleInterop: true, diff --git a/source/test/fixtures/dom/index.d.ts b/source/test/fixtures/dom/index.d.ts new file mode 100644 index 00000000..2aeae7f4 --- /dev/null +++ b/source/test/fixtures/dom/index.d.ts @@ -0,0 +1 @@ +export default function(parent: HTMLElement, child: HTMLElement): void; diff --git a/source/test/fixtures/dom/index.js b/source/test/fixtures/dom/index.js new file mode 100644 index 00000000..9b86b161 --- /dev/null +++ b/source/test/fixtures/dom/index.js @@ -0,0 +1,3 @@ +exports.default = (parent, child) => { + parent.appendChild(child); +}; diff --git a/source/test/fixtures/dom/index.test-d.ts b/source/test/fixtures/dom/index.test-d.ts new file mode 100644 index 00000000..ade5c04c --- /dev/null +++ b/source/test/fixtures/dom/index.test-d.ts @@ -0,0 +1,7 @@ +import {expectType} from '../../../..'; +import append from '.'; + +const parent = document.createElement('div'); +const child = document.createElement('p'); + +expectType(append(parent, child)); diff --git a/source/test/fixtures/dom/package.json b/source/test/fixtures/dom/package.json new file mode 100644 index 00000000..d88f069d --- /dev/null +++ b/source/test/fixtures/dom/package.json @@ -0,0 +1,8 @@ +{ + "name": "foo", + "tsd": { + "compilerOptions": { + "lib": ["dom"] + } + } +} diff --git a/source/test/test.ts b/source/test/test.ts index d8d7697f..97de449d 100644 --- a/source/test/test.ts +++ b/source/test/test.ts @@ -111,6 +111,14 @@ test('add support for esm with esModuleInterop', async t => { verify(t, diagnostics, []); }); +test('add DOM support by default', async t => { + const diagnostics = await tsd({ + cwd: path.join(__dirname, 'fixtures/dom') + }); + + verify(t, diagnostics, []); +}); + test('a lib option in package.json overrdides a lib option in tsconfig.json', async t => { const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/lib-config/lib-from-package-json-overrides-tsconfig-json')});