Typescript 接口合并与导入&;当地人不工作?

Typescript 接口合并与导入&;当地人不工作?,typescript,typescript-typings,Typescript,Typescript Typings,接口合并的示例表明,可以在单个文件中合并接口。 但当接口位于不同文件中时,我无法合并它们 请注意,我没有扩充任何模块,没有模块,只有接口 /类型/索引d.ts export interface A { baseline: string } /someFile.ts import {A} from './types/index'; // <-- Error "Import declaration conflicts with local declaration of 'A'" import

接口合并的示例表明,可以在单个文件中合并接口。 但当接口位于不同文件中时,我无法合并它们

请注意,我没有扩充任何模块,没有模块,只有接口

/类型/索引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 {}

从“/types/index”导入{A};// 记录答案,以便将来其他人更容易看到

您可以在导入时提供别名,如下所示

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

interface A {
  someAdditionalFlavor: FancyInterface
}

// Then use distinct A or ImportedA

您可以为导入提供别名<代码>从“…”导入{A as ImportedA}