正确的ES6导入以添加力矩精确范围插件

fid*_*dev 0 javascript momentjs typescript ecmascript-6 angular

我在angular 4项目中使用打字稿,并想使用moment-precise-range-plugin。

我已moment按照https://momentjs.com/docs/#/use-it/typescript/进行安装,但我想添加精确范围插件http://momentjs.com/docs/#/plugins/preciserange/

用于Precisionrange插件的Node.js的安装位于https://codebox.org.uk/pages/moment-date-range-plugin并指定require('moment-precise-range-plugin');但未安装Typescript。

我已经尝试过import { Moment } from 'moment-precise-range-plugin';但出现以下打字稿错误

Could not find a declaration file for module 'moment-precise-range-plugin'. 'c:/Users/[UserName]/app/node_modules/moment-precise-range-plugin/moment-precise-range.js' implicitly has an 'any' type. Try npm install @types/moment-precise-range-plugin if it exists or add a new declaration (.d.ts) file containing declare module 'moment-precise-range-plugin';'

任何想法都非常欢迎!

小智 5

我在Angular 4项目中使用了moment-precise-range-plugin,并且能够使用以下命令导入它:

import 'moment-precise-range-plugin';
Run Code Online (Sandbox Code Playgroud)

我在导入后导入了它: import * as moment from 'moment';

需要注意的一件事:我的TS linter仍然警告我这preciseDiff()会引起问题,但是一切都很好。试试看,看看是否可行。