无法导入已导出两次的类(Typescript)

无法导入已导出两次的类(Typescript),typescript,Typescript,我无法导入已导出两次的类 a.ts import * as moduleB from "./b"; export class A { b: moduleB.B; constructor() { this.b = new moduleB.B(); this.b.hello(); } } import {C} from "./c"; export const B = C; export class C { hello() { console.log("he

我无法导入已导出两次的类

a.ts

import * as moduleB from "./b";
export class A {
  b: moduleB.B;
  constructor() {
    this.b = new moduleB.B();
    this.b.hello();
  }
}
import {C} from "./c";
export const B = C;
export class C {
  hello() {
    console.log("hello");
  }
}
b.ts

import * as moduleB from "./b";
export class A {
  b: moduleB.B;
  constructor() {
    this.b = new moduleB.B();
    this.b.hello();
  }
}
import {C} from "./c";
export const B = C;
export class C {
  hello() {
    console.log("hello");
  }
}
c.ts

import * as moduleB from "./b";
export class A {
  b: moduleB.B;
  constructor() {
    this.b = new moduleB.B();
    this.b.hello();
  }
}
import {C} from "./c";
export const B = C;
export class C {
  hello() {
    console.log("hello");
  }
}
错误消息是:

a.ts(3,14): error TS2305: Module '"b"' has no exported member 'B'.
问题似乎是C的类型可能没有使用“export const B=C;”导出。如果我将“b:moduleB.b;”更改为“b:any;”,错误就会消失。 我怎样才能解决这个问题


在b.ts中使用默认导出将起作用,但我想在b.ts中导出一些内容,因此这不是一个选项。当您在
a.ts
中声明属性
b:moduleB.b
时,我使用的是Typescript 1.7.5.

,您将
b
定义为
moduleB.b
类型,但您将
moduleB.b
定义为常量。由于const是对
C
的构造函数的引用,因此
newmoduleb.B()
会编译

您可以改为在
B.ts
中编写
export type B=C
,但这样只会导出类型别名,这意味着
B:moduleB.B
将编译,但
new moduleB.B()
不会,因为您没有导出构造函数


B.ts
中使用
export{C as B}
(完整别名)可以完全实现您想要实现的目标。

太好了。这解决了我的问题。我不知道这种导出语法。