Why I can't use the node.js module 'date-fns'?

Discussão em 'Angular' iniciado por User051209, Outubro 23, 2024.

  1. User051209

    User051209 Guest

    I'm trying to use the format function of the Node.js module date-fns.

    Some info about my system (obtained by the command ng --version) is reported below:

    Angular CLI: 13.2.0
    Node: 16.13.2
    Package Manager: npm 8.6.0
    OS: linux x64


    I have installed date-fns by the command:

    npm install date-fns


    I have written an example file test_typescript.ts with the following code:

    import { format } from 'date-fns';

    const currentDate: Date = new Date();
    const formattedDate: string = format(currentDate, 'dd/MM/yyyy HH:mm');
    console.log(formattedDate);


    If I try to compile it by the following command:

    tsc src/test_typescript.ts


    I obtain the following error:

    node_modules/date-fns/clamp.d.ts:18:59 - error TS1005: '?' expected.
    18 Options extends ClampOptions<infer DateType extends Date>
    ~

    node_modules/date-fns/closestTo.d.ts:18:63 - error TS1005: '?' expected.
    18 Options extends ClosestToOptions<infer DateType extends Date>
    ~

    node_modules/date-fns/interval.d.ts:21:62 - error TS1005: '?' expected.
    21 Options extends IntervalOptions<infer DateType extends Date>
    ~
    Found 3 errors.


    The problem is in the import. How can I solve it?

    Continue reading...

Compartilhe esta Página