Javascript 正确的ES6导入以添加矩精确范围插件
我在angular 4项目中使用typescript,希望使用矩精确范围插件 我已经安装了MomentFollowing,但我想添加preciserange插件 preciserange插件的Install for Node.js位于,并指定需要'moment-precise-range-plugin';但是没有安装Typescript 我尝试从“矩精确范围插件”导入{Moment};但是得到下面的typescript错误 找不到模块“矩精确范围插件”的声明文件c:/Users/[UserName]/app/node_modules/moment-precise-range-plugin/moment-precise-range.js'隐式具有“any”类型。如果存在,请尝试npm安装@types/moment-precise-range-plugin,或者添加一个包含声明模块'moment-precise-range-plugin';'Javascript 正确的ES6导入以添加矩精确范围插件,javascript,angular,typescript,ecmascript-6,momentjs,Javascript,Angular,Typescript,Ecmascript 6,Momentjs,我在angular 4项目中使用typescript,希望使用矩精确范围插件 我已经安装了MomentFollowing,但我想添加preciserange插件 preciserange插件的Install for Node.js位于,并指定需要'moment-precise-range-plugin';但是没有安装Typescript 我尝试从“矩精确范围插件”导入{Moment};但是得到下面的typescript错误 找不到模块“矩精确范围插件”的声明文件c:/Users/[UserNam
任何想法都非常欢迎 我在Angular 4项目中使用了力矩精确范围插件,并能够通过以下方式导入:
import 'moment-precise-range-plugin';
我在导入瞬间后导入了它:导入*作为“瞬间”的瞬间
有一件事需要注意:我的TS linter仍然警告我preciseDiff会引起问题,但它运行得很好。尝试一下,看看它是否有效。我正在Angular 4项目中使用力矩精确范围插件,并能够通过以下方式导入它:
import 'moment-precise-range-plugin';
我在导入瞬间后导入了它:导入*作为“瞬间”的瞬间
有一件事需要注意:我的TS linter仍然警告我preciseDiff会引起问题,但它运行得很好。试试看它是否有效。我通过在src/typings.d.ts中添加一个定义文件修复了它
import * as moment from 'moment';
export = moment;
declare module 'moment' {
interface Moment {
preciseDiff(start: string | Date | moment.Moment): string;
}
}
我通过在src/typings.d.ts中添加一个定义文件来修复它
import * as moment from 'moment';
export = moment;
declare module 'moment' {
interface Moment {
preciseDiff(start: string | Date | moment.Moment): string;
}
}
注意:我使用的是角度10 它与我一起工作时,导入它作为->导入'时刻精确范围插件' 并添加以下3行:
declare module 'moment' {
function preciseDiff(start: string | Date | moment.Moment, end: string | Date | moment.Moment, convertToObject?: boolean): any;
}
注意:我使用的是角度10 它与我一起工作时,导入它作为->导入'时刻精确范围插件' 并添加以下3行:
declare module 'moment' {
function preciseDiff(start: string | Date | moment.Moment, end: string | Date | moment.Moment, convertToObject?: boolean): any;
}
对于angular 7,将@types/moment精确范围插件添加到项目中以保持编译。对于angular 7,将@types/moment精确范围插件添加到项目中以保持编译。