我遇到了一个问题:
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');
有何想法?