-
Notifications
You must be signed in to change notification settings - Fork 12.8k
program.getResolvedTypeReferenceDirectives()
not keyed by containing file/directory, leading to invalid declaration emit
#56836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@andrewbranch hey! I would like to work on this if you could please assign me |
This is true, but also intentional, ish. It's been this way for a long time, anyway. The common case here is |
With #57681 we stopped using resolved project reference maps to generate typeRef all together so this has become irrelevant now? |
The API is still used in a potentially unsafe way in |
That is just bug with incorrect usage and i am fixing that as part of some typeRef work i am doing. #58527 |
Test case
Expected behavior
Declaration files should be error-free if running
tsc --declaration
did not produce errors. Specifically, either/index.d.ts
should contain a triple-slash reference to"direct-dep"
, or compiling should produce an error saying that a portable reference to/node_modules/direct-dep/node_modules/transitive-dep/index.d.ts
cannot be emitted.Actual behavior
/index.d.ts
contains/// <reference types="transitive-dep" />
which does not resolve. No errors are produced while compiling.
Discussion
The erroneous type reference directive is emitted because the program stores information that the target file,
/node_modules/direct-dep/node_modules/transitive-dep/index.d.ts
, had previously been resolved by a type reference directive of"transitive-dep"
somewhere in the program’s input files. The declaration emitter mistakenly assumes that any type reference directive that resolved anywhere in the program will be resolvable from the declaration file it’s emitting, but this is a bad assumption because type reference resolution is dependent on the location of the file that’s making the resolution. In the test case above, the location that originally had the reference to"transitive-dep"
has anode_modules
folder in scope for its lookup that is not in scope for/index.d.ts
.This cannot reliably be fixed with a simple change to the declaration emitter, because the Program itself discards the relevant information about the location from which type reference directives were resolved. Its cache is keyed only by name and resolution mode.
I discovered this while attempting to make a package that uses conditional package.json
"exports"
to conditionally load ts-expose-internals. It fails because tsc writes invalid triple-slash references to"ts-expose-internals"
instead of to my proxy package.cc @sheetalkamat @weswigham for input
The text was updated successfully, but these errors were encountered: