admin管理员组文章数量:1404950
I'm using typescript within an angular 4 project and want to use moment-precise-range-plugin.
I've installed moment
following / but i want to add the preciserange plugin /.
Install for Node.js for the preciserange plugin is at and specifies require('moment-precise-range-plugin');
but there is no Typescript install.
I've tried import { Moment } from 'moment-precise-range-plugin';
but get the following typescript error
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';'
Any ideas very much wele!
I'm using typescript within an angular 4 project and want to use moment-precise-range-plugin.
I've installed moment
following https://momentjs./docs/#/use-it/typescript/ but i want to add the preciserange plugin http://momentjs./docs/#/plugins/preciserange/.
Install for Node.js for the preciserange plugin is at https://codebox.uk/pages/moment-date-range-plugin and specifies require('moment-precise-range-plugin');
but there is no Typescript install.
I've tried import { Moment } from 'moment-precise-range-plugin';
but get the following typescript error
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';'
Any ideas very much wele!
Share edited Aug 3, 2017 at 9:12 fidev asked Jul 28, 2017 at 17:35 fidevfidev 1,2523 gold badges24 silver badges53 bronze badges 03 Answers
Reset to default 7I'm using the moment-precise-range-plugin in an Angular 4 project and was able to import it with:
import 'moment-precise-range-plugin';
I imported it after importing moment: import * as moment from 'moment';
One thing to note: my TS linter still warns me that preciseDiff()
will cause problems, but it all runs just fine. Try that out and see if it works.
NOTE: I'm using Angular 10.
It works with me when import it as -> import 'moment-precise-range-plugin';
and add these 3 lines:
declare module 'moment' {
function preciseDiff(start: string | Date | moment.Moment, end: string | Date | moment.Moment, convertToObject?: boolean): any;
}
I fixed it by adding a definition file in src/typings.d.ts
import * as moment from 'moment';
export = moment;
declare module 'moment' {
interface Moment {
preciseDiff(start: string | Date | moment.Moment): string;
}
}
本文标签: javascriptcorrect ES6 import for adding moment precise range pluginStack Overflow
版权声明:本文标题:javascript - correct ES6 import for adding moment precise range plugin - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744855903a2628769.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论