【问题标题】:Import non typescript library using ES6 import使用 ES6 导入导入非 typescript 库
【发布时间】:2017-03-11 16:08:18
【问题描述】:

如何使用 ES6 import 语句导入非 typescript 库

import {observable, action, computed, transaction} from "mobx";

import lib from "somelib"

【问题讨论】:

    标签: typescript tsx


    【解决方案1】:

    有几种方法取决于代码的模块化方式。使用带有 ES6 样式模块声明的结构良好的库,例如 lodash,您可以按预期使用 ES6 导入语句,尽管它们不使用 TypeScript:

    import * from "lodash" as _;
    

    对于其他库,您可以像往常一样只 require 库并将其分配给导入:

    import lib = require("somelib");
    

    【讨论】:

    • 第二个选项对我有用,只是为 require 函数添加了一个 declare function require(name: string): any;谢谢法拉兹!!!
    猜你喜欢
    • 1970-01-01
    • 2018-11-17
    • 2017-08-06
    • 2015-08-13
    • 2018-04-15
    • 2018-02-02
    • 2017-12-03
    • 1970-01-01
    • 2016-04-09
    相关资源
    最近更新 更多