Skip to content

Fix references to path-mapped ambient modules in declaration files - #32878

Merged
Wesley Wigham (weswigham) merged 2 commits into
microsoft:masterfrom
weswigham:relative-refs-monorepo
Aug 13, 2019
Merged

Fix references to path-mapped ambient modules in declaration files#32878
Wesley Wigham (weswigham) merged 2 commits into
microsoft:masterfrom
weswigham:relative-refs-monorepo

Conversation

@weswigham

Copy link
Copy Markdown
Member

Fixes #26863

With this change, we now attempt to use a non-relative reference to a declaration file, if possible, before emitting a relative reference.


//// [index.d.ts]
/// <reference types="@ts-bug/a" />
export declare function b(text: string): import("@ts-bug/a").AText;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, since the import is import("@ts-bug/a"), we don't need the /// <reference types="@ts-bug/a" />, since they refer to the "same" thing (or at least cause the same file to be found and included). However since the import could be something like @ts-bug/a/b (which could be an ambient module in @ts-bug/a), we can't generally elide the reference. A cleanup pass where we remove types directives which exactly match an import somewhere in the file may be pertinent.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my old friend moduleSpecifiers.getModuleSpecifier, we meet again.

@weswigham
Wesley Wigham (weswigham) merged commit 602966b into microsoft:master Aug 13, 2019
@weswigham
Wesley Wigham (weswigham) deleted the relative-refs-monorepo branch August 13, 2019 23:34
@weswigham

Wesley Wigham (weswigham) commented Aug 13, 2019

Copy link
Copy Markdown
Member Author

Ryan Cavanaugh (@RyanCavanaugh) Daniel Rosenwasser (@DanielRosenwasser) wanna have this ported this to 3.6 (since it was in the 3.6 milestone)?

@weswigham

Copy link
Copy Markdown
Member Author

TypeScript Bot (@typescript-bot) cherry-pick this into release-3.6

@typescript-bot

Copy link
Copy Markdown
Contributor

Hey Wesley Wigham (@weswigham), I've opened #32881 for you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relative reference in generated .d.ts file in a monorepo

3 participants