我通过typings安装了moment的定义文件:
typings install moment --save 一切都很顺利,但是当我按照以下方式导入定义时:
import * as moment from 'moment';
编译一切正常,但是当我运行应用程序时,我收到一个运行时错误:
Uncaught TypeError: moment is not a function
moment库应该如何导入呢?
如果我改用以下方式:
const moment = require('moment');
一切都正常,但我失去了所有类型安全性。
我的tsconfig.json:
typings install moment --save 一切都很顺利,但是当我按照以下方式导入定义时:
import * as moment from 'moment';
编译一切正常,但是当我运行应用程序时,我收到一个运行时错误:
Uncaught TypeError: moment is not a function
moment库应该如何导入呢?
如果我改用以下方式:
const moment = require('moment');
一切都正常,但我失去了所有类型安全性。
我的tsconfig.json:
{
"compilerOptions": {
"jsx": "preserve",
"target": "ES6",
"declaration": false,
"module": "es2015",
"experimentalDecorators": true,
"sourceMap": true,
"noLib": false,
},
"exclude": [
"node_modules",
"meteor_core",
"typings/browser",
"typings/browser.d.ts"
]
}
非常感谢您的帮助。
tsconfig.json
文件。 - Fidan Hakaj