Skip to content

Importing a type with same name as an export #31031

Closed

Description

TypeScript Version: 3.5.0-dev.20190419

Search Terms: import export conflict priority

Code

/// foo.ts
export interface Foo { a: number; }

/// test.ts
import { Foo } from './foo'
export interface Foo { b: number; }
let foo: Foo = { a: 2 }

Expected behavior: Declaration conflict on test.ts (imported Foo vs exported Foo).

Actual behavior: No error. Instead, (see last line) Foo refers to the imported Foo, and the exported Foo becomes unaccessible. Is this expected?

If export interface is changed to export class, then a declaration conflict appears.
If export is removed in initial case, a declaration conflict also appears.

Playground Link: I don't know how to reproduce this with one file.

Related Issues: I searched issues, stackoverflow and docs (declaration merging, imports and exports, namespaces) but couldn't find any references to this behaviour.

Activity

  1. collin5 commented on Apr 30, 2019

    @collin5
    Contributor

    Hmm, I see. Will be taking a crack at this by end of the week.

  2. collin5 commented on May 3, 2019

    @collin5
    Contributor

    Raised a PR to attempt resolving this (#31231). One thing to note is that this was introduced by #7591 because of possible breakage from #7583. Not sure if this still holds though.

  3. 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

Assignees

No one assigned

    Labels

    Breaking ChangeWould introduce errors in existing codeBugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions