Skip to content

Duplicated type leads TSC to pick the wrong one in the *.d.ts file (for implicit return type) #25731

@lorem--ipsum

Description

@lorem--ipsum

TypeScript Version: ^2.9.2 (also tested with @next with no difference)

Search Terms:
duplicated type, implicit return, type definition file

Code

// component-a/component-a.tsx
export type ComponentAPosition = 'top' | 'bottom' | 'left' | 'right';

export class ComponentA {
  doAThing(value: ComponentAPosition) {}
}

// component-b/component-b.tsx
export type ComponentBPosition = 'top' | 'right' | 'bottom' | 'left';

export class ComponentB {
  doSomething(values: ComponentBPosition) {
    return values;
  }
}

Expected behavior:

// component-b.d.ts
export declare type ComponentBPosition = 'top' | 'right' | 'bottom' | 'left';
export declare class ComponentB {
    doSomething(values: ComponentBPosition): ComponentBPosition;
}

Actual behavior:

// component-b.d.ts
export declare type ComponentBPosition = 'top' | 'right' | 'bottom' | 'left';
export declare class ComponentB {
    doSomething(values: ComponentBPosition): import("../component-a/component-a").ComponentAPosition;
}

Playground Link: Not a playground, but a repo (run npm i && tsc, although the output is in the repo anyway under the build/ directory): https://github.com/lorem--ipsum/tsc-test

Related Issues: -

Thoughts:
The file that gets its type definition is component-b.tsx. It needs to be compiled after component)-a.tsx (I assume the order is alphabetical). The bug does happen when running tsc --watch, but only on the first run, not when component-b.tsx is changed. The returned type is correct when stated explicitly in the source file. It doesn't occur either when the two types (ComponentAPosition and ComponentBPosition aren't strictly similar).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions