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
{{ message }}
Repository navigation
triple-slash reference added only if another triple-slash reference exists #57482
// @declaration: true// @filename: /a/node_modules/extra/index.d.tsinterfaceError2{stack2: string;}// @filename: /a/node_modules/something/index.d.ts/// <reference types="extra" />// ^ remove above and it will no directive will be added to app.d.tsexportfunctionfoo():Error2;// @filename: /a/app.ts// reference to extra will be added here if there exists another reference to extraexportfunctionfoo(){returnnull!asError2;}
🙁 Actual behavior
/// <reference types="extra" /> is added to app.d.ts only if another reference directive to extra already exists (in this example one from node_modules)
🙂 Expected behavior
/// <reference types="extra" /> is always added since extra is required for app.d.ts to be valid
Additional information about the issue
This was discovered while trying to understand reference directives in the context of isolated declarations.
I feel like I recently stumbled across a piece of code that doesn’t add type reference directives if the types are found in typeRoots, but I don’t remember exactly where that was, and it feels unjustifiable to me.
This seems to be intentional, but I still don't understand why:
// checker.tsfunctiongetTypeReferenceDirectivesForEntityName(node: EntityNameOrEntityNameExpression): [specifier: string,mode: SourceFile["impliedNodeFormat"]|undefined][]|undefined{// program does not have any files with type reference directives - bail outif(!fileToDirective){returnundefined;}
Also fileToDirective is populated from the host (const resolvedTypeReferenceDirectives = host.getResolvedTypeReferenceDirectives();) and getResolvedTypeReferenceDirectives just returns the cache of reference directives that were found while parsing the program SourceFiles.
This code seems to be really old (2016 by Vladimir Matveev)
Activity
dragomirtitian commentedon Feb 22, 2024
Andrew Branch (@andrewbranch) do you have any insight on if this behavior is intentional?
andrewbranch commentedon Feb 22, 2024
I feel like I recently stumbled across a piece of code that doesn’t add type reference directives if the types are found in
typeRoots, but I don’t remember exactly where that was, and it feels unjustifiable to me.dragomirtitian commentedon Feb 22, 2024
This seems to be intentional, but I still don't understand why:
Also
fileToDirectiveis populated from thehost(const resolvedTypeReferenceDirectives = host.getResolvedTypeReferenceDirectives();) andgetResolvedTypeReferenceDirectivesjust returns the cache of reference directives that were found while parsing the programSourceFiles.This code seems to be really old (2016 by Vladimir Matveev)