Compiling with -d should emit triple-slash lib paths #28195
Labels
Fix Available
A PR has been opened for this issue
In Discussion
Not yet reached consensus
Suggestion
An idea for TypeScript
Search Terms
Triple slash, reference, path, lib, library, types, typings, dom
Suggestion
When compiling a .ts file with
declaration: true
, TSC should emit triple-slash reference paths for alllib
s consumed by the .ts file.Problem
Say I publish typings for my package
foo
to NPM, andfoo
depends on DOM typings. I then includefoo
in my project (npm install foo
). There are a few things that can happen:foo
's typings include<reference lib="dom" />
:foo
has access to DOMdom
(or uses the same triple-slash directive as in 1):foo
has access to DOMfoo
include<reference lib="dom" />
:foo
errors wherever it uses DOM types (but I have to inspect node_modules/foo/index.d.ts to see those errors)My project treats
foo
's DOM types asany
s (should this error instrict
mode?)Solution
If
tsc -d
generated triple-slash directives forfoo/index.d.ts
, we can ensure that we're always in case (1). This is nice because if my project doesn't usedom
, I shouldn't have to declare it for the sake offoo
like I did in (2); it also avoids theany
from (3).An open question is how strict should TSC be? Ie. If
foo
usesdom
but fails to reference it, should this cause a compile error in my project (and a nice message suggesting I add a reference todom
)?Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: