Skip to content

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

Description

@wgcrouch

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

Activity

  1. RyanCavanaugh commented on Mar 13, 2019

    @RyanCavanaugh
    Member

    Probably a duplicate of the linked related issue

  2. sebinsua commented on Mar 14, 2019

    @sebinsua

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

  3. andypillip commented on Jul 15, 2019

    @andypillip

    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> {

  4. weswigham commented on Aug 13, 2019

    @weswigham
    Member

    Andy Pillip (@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.

  5. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions