如何在不导入的情况下创建 class 的实例

How to use create an instance of a class without importing it

我使用导入语句在我的 TypeScript 应用程序中导入大多数 classes:

import {Logger, getLogger} from "aurelia-logging";
import {HttpResponseMessage} from "aurelia-http-client";

class ErrorHandler {
    logger:Logger = getLogger("Error-Handler");
    handleError(message: any) : void {
        this.logger.error(message);
    }
    handleHttpError(response: HttpResponseMessage) {
        this.logger.error(response.content.error_description);
    }
}

但是,我发现了一些可以执行此操作的示例代码:

entityManager = new breeze.EntityManager(Settings.serviceName);

但是,breeze 未导入任何地方。

我不明白这是怎么回事。 breeze 有一个 .d.ts 文件,但我没有看到它被导入到项目的任何地方。 Visual Studio 将 "breeze" 识别为命名空间,将 EntityManager 识别为 class。我相信它是直接从 TDF 获得的。

class EntityManager {...}

此外 class 未导出。我认为它必须导出:

export class EntityManager{...}

似乎不​​必使用 import/export 语句要简单得多,但我不明白这是如何实现的。

I don't get how that works. There is a .d.ts file for breeze, but I don't see anywhere that it is imported anywhere in the project

如果库污染(使用)全局命名空间,它将起作用。当前 breeze 定义:https://github.com/borisyankov/DefinitelyTyped/blob/44cbde48eecd1918ed54b3be49a9752688b6c65a/breeze/breeze.d.ts works globally. Its a global module as there is no import/export at the root level (more).

运行时也是如此(通过添加到 window)。