【问题标题】:How to get toastr to work in Typescript如何让 toastr 在 Typescript 中工作
【发布时间】:2015-11-25 22:13:09
【问题描述】:

我正在将一个项目转换为 Typescript。我在使用 toastr 时遇到问题。

import {toastr} from "toastr";

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

文件末尾有这个导出:

declare var toastr: Toastr;
declare module "toastr" {
export = toastr;
}

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

我该如何解决这个问题?

【问题讨论】:

    标签: typescript toastr


    【解决方案1】:

    尝试以下方法:

    import * as toastr from "toastr";
    

    这样做会将整个模块导入为toastr

    【讨论】:

    • 另外,添加@types/toastr 会增加打字稿类型! (npm install --save @types/toastr)
    • 不应该是 --save-dev 吗?
    • 这行得通。然后像toastr.info('something') 一样使用它
    猜你喜欢
    • 1970-01-01
    • 2023-01-18
    • 2021-12-29
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多