Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

index.d.ts should be the only d.ts file allowed in tsconfig.json #708

@sandersn

Description

@sandersn

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:

  1. dtslint will need a rule that checks tsconfig and disallows all d.ts except index.d.ts.
  2. 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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions