Skip to content

Commit

Permalink
Fix inclusion of module-augmenting .d.ts's (#761)
Browse files Browse the repository at this point in the history
A previous commit updated the TypeScript configuration so TypeScript
would better recognize type definition files whose purpose was to
backfill types for existing packages. After testing, this revealed a
misunderstanding of the `paths` option in `tsconfig.json`.

It turns out that `paths` completely overrides how TypeScript resolves
modules and locates type definition files for modules. The consequence
of this option is that if a module includes type definitions, but we
also supply type definitions for that module in `types/`, then our type
definitions will win. This degrades the developer experience: sometimes,
a package already has types, but we merely need to *augment* those
types in some way. The `paths` option makes it impossible to do this.

This commit keeps the `types/` directory (as it'll be important later)
but informs TypeScript about the type definition files here by adding
them to the `include` option in `tsconfig.json` (which was the original
strategy).
  • Loading branch information
mcmire authored Apr 5, 2022
1 parent 6f3808b commit 5f2d51c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
1 change: 0 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["./src/**/*.ts"],
"exclude": ["**/*.test.ts"]
}
6 changes: 2 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
"inlineSources": true,
"module": "commonjs",
"moduleResolution": "node",
"paths": {
"*": ["./types/*"]
},
"sourceMap": true,
"strict": true,
"target": "es6"
}
},
"include": ["./types/**/*.d.ts", "./src/**/*.ts"]
}

0 comments on commit 5f2d51c

Please sign in to comment.