Base solution for your next web application
Open Closed

Extending typings for moment #3705


User avatar
0
bilalhaidar created

Hello, I need your assistance with extending the moment typings.

I need to use this moment plugin: <a class="postlink" href="https://github.com/codebox/moment-precise-range">https://github.com/codebox/moment-precise-range</a>

This plugin adds a preciseDiff() function to the moment object.

Now, how can I add typings for this function? I need to extend the moment.d.ts so that I can start using the preciseDiff() function.

Can you assist me? That plugin has no typings and hence I need to do something about it. I tried to add the following in the typings.d.ts file.

/**
 * moment-precise-range
 */
declare module 'myMoment' {
    export namespace moment {
        export function preciseDiff(...any): any;
    }
}

Then in the code I would use something as:

import * as myMoment from 'myMoment';

myMoment.moment.preciseDiff()

No compilation errors, but when "ng serve" runs, I get this exception:

Module not found: Error: Can't resolve 'myMoment' in 'D:\Projects\...\app\sms\poc-edit'

Appreciate your help.

Thanks Bilal


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @bilalhaidar,

    I think it is better to seek help from <a class="postlink" href="https://github.com/codebox/moment-precise-range">https://github.com/codebox/moment-precise-range</a> because this is not related to AspNet Zero.

    Thanks.