[英]Export namespace with other name in TypeScript
在下面的示例中,我希望將合並的 class ConsoleCommandsParser
和命名空間ConsoleCommandParserTypes
為ConsoleCommandsParser
。 很簡單,它都在一個文件中聲明,但這是另一種情況。
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;
試試下面的代碼,我已經在我的類型腳本文件中測試過了
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);
讓我知道這是否對您不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.