Skip to content
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

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

Closed
wgcrouch opened this issue Sep 3, 2018 · 4 comments · Fixed by #32878
Closed

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

wgcrouch opened this issue Sep 3, 2018 · 4 comments · Fixed by #32878
Assignees
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Fix Available A PR has been opened for this issue

Comments

@wgcrouch
Copy link

wgcrouch commented Sep 3, 2018

When generating a .d.ts file, typescript is including a relative reference for an import, which is imported as a module.

import { a } from "@ts-bug/a";

export function b(text: string) {
  return a(text);
}

generated a definition file:

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

In this case it is in a mono-repo which may be confusing things, but the reference should be the same as the import.

TypeScript Version:
3.0.3, but also happens with 3.1.0-dev.20180901

Search Terms:
relative reference paths
generated reference relative

Code
I have created a repo with a simple reproduction here https://github.com/wgcrouch/ts-bug

Expected behavior:
The reference /// <reference types="@ts-bug/a" />

Actual behavior:
The reference generated is /// <reference path="../../a/index.d.ts" />

Related Issues:
#26439

@RyanCavanaugh
Copy link
Member

Probably a duplicate of the linked related issue

@sebinsua
Copy link

@RyanCavanaugh Yes - but this one has a reproduction repository so it should be easier for somebody to get to the root cause on.

@andypillip
Copy link

andypillip commented Jul 15, 2019

In my case the generated .d.ts file contains syntax errors – is that related to this issue?

/// <reference path="../../../../../../../../node_modules/@types/moduleE/dist/index.d.ts" />

declare const myFunc: () => O<'moduleE'.E<any>>;

The above is invalid, hence definitely a bug.

The file causing this error is as follows:

declare module 'moduleE' {
    export interface E<T> {

If I remove the declare module, it's at least generating an @import() around the module name.

And if I replace the arrow function by a regular function, everything works:
export function myFunc(): MyResult<any> {

@weswigham
Copy link
Member

@andypillip if you could open up a new issue with a repro, that's be great, it's definitely not (directly) related to the issue in the OP here.

@weswigham weswigham added the Fix Available A PR has been opened for this issue label Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants