如何让toastr在Typescript中工作

Gre*_*Gum 7 typescript toastr

我正在将项目转换为Typescript.我遇到了toastr的问题.

import {toastr} from "toastr";
Run Code Online (Sandbox Code Playgroud)

我用Nuget下载了typescript定义文件并将其包含在项目中.

它在文件末尾有这个导出:

declare var toastr: Toastr;
declare module "toastr" {
export = toastr;
}
Run Code Online (Sandbox Code Playgroud)

但是,我得到编译时错误: Modle "toastr" has no exported member 'toastr'

我该如何解决这个问题?

Dav*_*ret 13

请尝试以下方法:

import * as toastr from "toastr";
Run Code Online (Sandbox Code Playgroud)

这样做会导入整个模块toastr.

  • 此外,添加@types/toastr 添加了打字稿类型!(npm install --save @types/toastr) (4认同)
  • 不应该是--save-dev而不是吗? (4认同)