Description
Search Terms
- lib / lib.dom.d.ts
- override / replace / substitute
- triple slash reference
- path
Suggestion
Provide a compiler option that allows the path to a lib file to be overridden. For example being able to provide a local path to lib.dom.d.ts
so that when the dom
lib is included, the local path is used rather than the version bundled with TypeScript.
Use Cases
I want to write a library that targets multiple environments (specifically node and web) that has type safety to ensure that globals (that only exist in one environment) are not unsafely referenced.
The current approach to copy lib.dom.d.ts
that comes with TypeScript and edit it to remove all declare const
lines, and then include it via include
and be sure not to include dom
in compilerOptions.lib
. The downside of this approach is that when an upstream type definition (e.g. @types/jsdom
) has a triple slash reference to the dom lib, the lib.dom.d.ts
bundled with TypeScript is included.
Examples
A new compilerOptions.libPaths
option would be available that would allow paths to libs to be overridden, e.g.
{
"compilerOptions": {
"libPaths": {
"dom": "./types/lib.dom-no-globals.d.ts"
}
}
}
This wouldn't implicitly include the dom
lib, it would still need to be explicitly included via compilerOptions.lib
or by a type definition using a triple slash lib reference /// <reference lib="dom" />
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.