Skip to content

Incorrect Path Resolution for Type Imports in TypeScript DeclarationsΒ #57956

Closed
@xlianghang

Description

@xlianghang

πŸ”Ž Search Terms

"specifier", "relative path"

πŸ•— Version & Regression Information

⏯ Playground Link

https://github.com/xlianghang/ts-specifier-bug

πŸ’» Code

//src/main.ts
import { PartialType } from './utils';

class Common {}

export class Sub extends PartialType(Common) {
  id: string;
}
// src/utils/index.ts
import { MyType, MyReturnType } from './type-helpers';

export function PartialType<T>(classRef: MyType<T>) {
  abstract class PartialClassType {
    constructor() {}
  }

  return PartialClassType as MyReturnType;
}
// src/utils/type-helpers.ts
export type MyReturnType = {
  new (...args: any[]): any;
};

export interface MyType<T = any> extends Function {
  new (...args: any[]): T;
}

πŸ™ Actual behavior

image

The dist folder is not the root directory, so do not import from src

πŸ™‚ Expected behavior

image

Import from a relative path

Additional information about the issue

Compilation fails in the MacOS, but is expected to behave in the https://stackblitz.com/~/github.com/xlianghang/ts-specifier-bug

πŸ’» MacOS 14.3,Apple M2 Max

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFix 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