0

在下面的示例中,我希望将合并的类ConsoleCommandsParser和命名空间导出ConsoleCommandParserTypesConsoleCommandsParser. 很简单,它都在一个文件中声明,但这是另一种情况。

import ConsoleCommandParserTypes from "./ConsoleCommandParserTypes";

export abstract class ConsoleCommandsParser {

  public static parse(arrayedConsoleCommand: Array<string>): void {
    // not implemented yet
  }
}

// Invalid syntax
export namespace ConsoleCommandParserTypes as ConsoleCommandParser;
// Namespace can not be used as value
export ConsoleCommandParser = ConsoleCommandParserTypes 
// Invalid syntax
export namespace ConsoleCommandParser = ConsoleCommandParserTypes;
4

1 回答 1

0

试试下面的代码,我已经在我的类型脚本文件中测试过了

namespace Test {
  export class Test1 {
    static xyz(xyz: any) {
      throw new Error("Method not implemented.");
    }
    xyz:string = "XYZ";
  }
  export class Test2 {
    abc:string = "ABC";
  }
}

// Use this to create an object and access the methods and variables, it works for me
let test1 = new Test.Test1;
console.log(test1.xyz);

让我知道这是否对您不起作用。

于 2020-04-08T01:39:51.710 回答