-
Notifications
You must be signed in to change notification settings - Fork 147
index.d.ts should be the only d.ts file allowed in tsconfig.json #708
Description
Currently, tsconfig.json for each package contains all the test files and all the type files. However, for the test files, this doesn't reflect how users will reference the type files as installed in @types/*. This matters when a package has a global augmentation:
// @filename: globals.d.ts
declare global {
function glo(n: number): void
}
// @filename: index.d.ts
export const x = 1
// @filename: package-tests.ts
import { x } from 'package'
// @filename: global-tests.ts
glo(1)When @types/package is actually installed, the last file, global-tests.ts, is incorrectly able to resolve glo without having
/// <reference types="package/globals" />
At the top. That's because the in-DT tsconfig currently looks like this:
...
"files": [
"index.d.ts",
"globals.d.ts",
"package-tests.ts",
"global-tests.ts"
]Only index.d.ts should be allowed of the types files:
...
"files": [
"index.d.ts",
"package-tests.ts",
"global-tests.ts"
]Everything else should be referenced either through index.d.ts or through an explicit reference in the tests. That's because users shouldn't have references in their "files" like node_modules/@types/package/global-tests.ts.
Fixing this will require a couple of changes:
- dtslint will need a rule that checks tsconfig and disallows all d.ts except
index.d.ts. - types-publisher will need to follow dependencies in tests too. Right now it doesn't.
d.ts files that aren't tested and aren't used need to be added to UNUSED_FILES.txt. Previously they could just be added to "files" in tsconfig. Because UNUSED_FILES.txt will not include files that might be used, but happen to have no tests, I'm going to rename it to OTHER_FILES.txt.
So, this bug will have five associated PRs:
- Types-publisher: Rename UNUSED_FILES.txt to OTHER_FILES.txt (Rename UNUSED_FILES to OTHER_FILES #709)
- Rename 6 UNUSED_FILES.txt to OTHER_FILES.txt in existing DT packages. (Rename UNUSED_FILES.txt to OTHER_FILES.txt DefinitelyTyped/DefinitelyTyped#40479)
- Types-publisher: start following references in tests for calculating unused files. (Follow test references to calculate unused files #710)
- Drop already-referenced files from about 250 tsconfig.jsons. (Trim tsconfig files; move untested files to OTHER_FILES.txt DefinitelyTyped/DefinitelyTyped#40676)
- Move unreferenced files from about 102 tsconfig.jsons to OTHER_FILES.txt. (Trim tsconfig files; move untested files to OTHER_FILES.txt DefinitelyTyped/DefinitelyTyped#40676)
- Document in README.md (Update new package instructions DefinitelyTyped/DefinitelyTyped#40677)
- File follow-up issue on Typescript for typeReference not respecting baseUrl/typeRoots (Triple slash type reference doesn't use baseUrl/typeRoots TypeScript#35365)
- Publicise change on Twitter.
- Check dts-gen to see how it generates the file list.
I combined the last two steps together because I believe that the change will not break DT. I sent out a series of small fixup PRs first.