interface merge with import & local not working?

Viewed 364

Examples of interface merging shown it is possible to merge interface in single file. But I cannot merge interfaces when they are in different files.

Note that I'm not augmenting any modules, no modules, just interface.

/types/index.d.ts

export interface A { baseline: string }

/someFile.ts

import {A} from './types/index'; // <-- Error "Import declaration conflicts with local declaration of 'A'"
import {FancyInterface} from './SomeClass'

interface A {
  someAdditionalFlavor: FancyInterface
}
export default class ABC implements A {}

I am intended to use the same interface name here, because they are literally the same interface, but since I am sharing the base interface with other modules, which I can't add FancyInstance there.

1 Answers

To record the answer and make easier to see it for others in the future.

You can provide an alias when importing, like so

import { A as ImportedA } from './types/index';
import { FancyInterface } from './SomeClass'

interface A {
  someAdditionalFlavor: FancyInterface
}

// Then use distinct A or ImportedA
Related