我正在尝试使用 Angular 2 和 Typescript 创建一个概念验证应用程序。我想合并toastr通知库,并希望有一种简单的方法可以让它在没有定义文件的情况下运行。
我在我的公共服务目录中创建了一个名为 toastr.d.ts] 的文件:
declare module "toastr" {
// var noTypeInfoYet: any;
// export = noTypeInfoYet;
}
从服务 common.ts 调用
/// <reference path="toastr.d.ts" />
import {Injectable} from 'angular2/core';
import {toastr} from 'toastr';
@Injectable()
export class Common {
constructor() {}
log(message:string){
toastr(message);
console.log(message);
}
}
但是我收到编译错误:[DiffingTSCompiler]:Typescript 发现以下错误:app/services/common/common.ts (3,9): Module '"toastr"' has no exported member 'toastr'。
所有代码都可以在Cloud 9上找到