diff --git a/package.json b/package.json index 149c7574..02cc7a9d 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,9 @@ "prepublishOnly": "npm run build", "pretest": "npm run build && cpy \"./**/**\" \"../../../dist/test/fixtures/\" --parents --cwd=source/test/fixtures", "test": "npm run lint && ava", - "build": "npm run clean && tsc && chmod +x dist/cli.js", + "build": "npm run clean && tsc --project tsconfig.tsd.json && chmod +x dist/cli.js", "clean": "del-cli dist", - "lint": "tslint -p . --format stylish" + "lint": "tslint -p tsconfig.tsd.json --format stylish" }, "files": [ "dist/index.js", diff --git a/source/lib/config.ts b/source/lib/config.ts index f478293c..dc565ab9 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: ['es2017', 'dom', 'dom.iterable'], + lib: parseRawLibs(['es2017', 'dom', 'dom.iterable'], cwd), module: ModuleKind.CommonJS, target: ScriptTarget.ES2017, esModuleInterop: true, @@ -67,3 +67,7 @@ function parseCompilerConfigObject(compilerOptions: RawCompilerOptions, cwd: str cwd ).options; } + +function parseRawLibs(libs: string[], cwd: string): string[] { + return parseCompilerConfigObject({lib: libs}, cwd).lib || []; +} diff --git a/source/test/fixtures/dom/index.test-d.ts b/source/test/fixtures/dom/index.test-d.ts index ade5c04c..59ff367d 100644 --- a/source/test/fixtures/dom/index.test-d.ts +++ b/source/test/fixtures/dom/index.test-d.ts @@ -5,3 +5,7 @@ const parent = document.createElement('div'); const child = document.createElement('p'); expectType(append(parent, child)); + +const elementsCollection = document.getElementsByClassName('foo'); +expectType>(elementsCollection); +expectType<() => IterableIterator>(elementsCollection[Symbol.iterator]); diff --git a/source/test/fixtures/dom/package.json b/source/test/fixtures/dom/package.json index d88f069d..de6dc1db 100644 --- a/source/test/fixtures/dom/package.json +++ b/source/test/fixtures/dom/package.json @@ -1,8 +1,3 @@ { - "name": "foo", - "tsd": { - "compilerOptions": { - "lib": ["dom"] - } - } + "name": "foo" } diff --git a/source/test/fixtures/lib-config/failure-missing-lib/package.json b/source/test/fixtures/lib-config/failure-missing-lib/package.json index de6dc1db..6e90f8d8 100644 --- a/source/test/fixtures/lib-config/failure-missing-lib/package.json +++ b/source/test/fixtures/lib-config/failure-missing-lib/package.json @@ -1,3 +1,8 @@ { - "name": "foo" + "name": "foo", + "tsd": { + "compilerOptions": { + "lib": [] + } + } } diff --git a/tsconfig.json b/tsconfig.tsd.json similarity index 100% rename from tsconfig.json rename to tsconfig.tsd.json