angular 5 个通知和 AOT

angular 5 noty and AOT

我正在以这种方式将 noty (https://ned.im/noty) 与 angular 5.2.9 一起使用:

import { Injectable } from '@angular/core';
import Noty = require('noty');

@Injectable()
export class NotificationService {
    private noty(options) {
        return new Noty(options).show();
    }
    ...
}

并且工作正常。

但是当我使用 AOT (npm run build:aot) 构建时,我得到:

ERROR in src/app/sys/util/notification.service.ts(2,1): error TS1202:  
Import assignment cannot be used when targeting ECMAScript modules.  
Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

这是一个基于https://github.com/gdi2290/angular-starter的项目。
使用 import Noty from 'noty'; 时,AOT 构建很好,但是当 运行 npm run server 我得到 ERROR TypeError: noty_1.default is not a constructor.

node_modules/noty/index.d.ts 开头为:

declare module 'noty' {
    export = Noty;
}

declare class Noty {
    constructor(options?: Noty.Options);
...

我该如何解决?

我发现它是这样工作的:

/// <reference path="../../../../node_modules/noty/index.d.ts" />

import { Injectable } from '@angular/core';
import Noty = require('noty');

@Injectable()
export class NotificationService {
    private noty(options) {
        return new Noty(options).show();
    }
    ...
}

因为 noty 没有将 d.ts 放入 node_modules/@types/...那么我想我必须手动引用它。

PS: 还要在tsling.json中设置"no-reference": false规则,否则会将引用标记为错误