我遇到了一个问题:
import moment from 'moment';
moment
本身是一个默认的CommonJS导出函数,在此编码https://github.com/borisyankov/DefinitelyTyped/blob/master/moment/moment.d.ts:
interface MomentStatic {
(): Moment;
(date: number): Moment;
...
}
declare var moment: moment.MomentStatic;
declare module 'moment' {
export = moment;
}
以下似乎不起作用:
import * from 'moment';
// error TS1005: 'as' expected.
// error TS1005: 'from' expected.
import moment from 'moment';
// error TS1192: External module ''moment'' has no default export.
import {default as moment} from 'moment';
// error TS2305: Module ''moment'' has no exported member 'default'.
require语法仍然有效......但我试图避免这种情况。
import moment = require('moment');
思想?
答案 0 :(得分:19)
您正在寻找的语法
import * as moment from "moment";