【问题标题】:Importing tcomb lib in Angular 2 / webpack app gives undefined在 Angular 2 / webpack 应用程序中导入 tcomb lib 给出未定义
【发布时间】:2017-03-21 12:10:58
【问题描述】:

导入tcomb 给出未定义:

import t from 'tcomb';
console.log(t); // undefined

// So this won't work
t.assert(t.Number.is(colorString), 'colorString is invalid argument');

不过我是这样工作的,其实我更喜欢这样:

import {assert, Number} from 'tcomb';
assert(Number.is(colorString), 'colorString is invalid argument');

将 all 导入为 t 仅返回 assert() 方法而不是完整对象

import * as t from 'tcomb';

我正在使用带有 webpack-dev-server、angular 2、typescript 和 HMR 的非常标准的设置。到目前为止,所有库都可以正常加载。该项目已经有几个月的历史了。

知道这里发生了什么吗?为什么tundefined

注意:即使我到处都有 TS 类型,我也在使用运行时检查,因为某些服务方法仍然可能在运行时收到错误的参数。作为旁注,tcomb 对我来说似乎很好,但只是为了学习,有没有比 tcomb 更好的选择?

【问题讨论】:

    标签: javascript tcomb


    【解决方案1】:

    你试过var t = require('tcomb')吗? 也许与不起作用的 es6 import 语句有关?

    【讨论】:

    • require 有效,但我希望使用 import 声明
    猜你喜欢
    • 2017-01-13
    • 1970-01-01
    • 2016-12-30
    • 2017-07-12
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多