You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.)
In my usage scenario, this (or similar) feature is also very useful. The problem is I cannot extend global variables that support multiple environments.
For example, I need to write test cases for my code running in the browser. I need to simulate a series of variables in the window in the node environment; but it is actually running in the browser. In order to make it work, lib.dom.d.ts is required; but this will cause a conflict, because I customized the window in Node, and this is in conflict with lib.dom.d.ts.
In use, I can manually write a lib.dom.d.ts, and then no longer introduced in compiler options, as @bradleyayers said; but if I want to write a library, this problem is difficult to solve.
Maybe a feature that can partially override lib's type can be provided?
Search Terms
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 thedom
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 alldeclare const
lines, and then include it viainclude
and be sure not to includedom
incompilerOptions.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, thelib.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.This wouldn't implicitly include the
dom
lib, it would still need to be explicitly included viacompilerOptions.lib
or by a type definition using a triple slash lib reference/// <reference lib="dom" />
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: