How to calculate XIRR in typescript? [@types/xirr is not available]

72 Views Asked by At

XIRR calculation in typescript

Here typescript package is not available: https://www.npmjs.com/search?q=%40types%2Fxirr

Getting this error:

npm i --save-dev @types/xirr
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fxirr - Not found
npm ERR! 404 
npm ERR! 404  '@types/xirr@*' is not in this registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
1

There are 1 best solutions below

0
youcef boudjenah On

It seems that there might not be TypeScript type definitions available for the XIRR package you're trying to use. If the package is not present in the DefinitelyTyped repository, you might need to create your own type definitions or use the package without TypeScript types.

Here are a few suggestions:

  1. Create Your Own Types: If you are familiar with the structure of the XIRR package, you can create your own TypeScript type definitions. Create a file, for example, xirr.d.ts, and declare the types there. Here is a basic example:

    declare module 'xirr' {
      function xirr(cashflows: number[], dates: Date[], guess?: number): number;
      export = xirr;
    }
    

    This is a simple example, and you might need to adjust it based on the actual structure of the XIRR package.

  2. Use the Package Without Types: If creating types is not feasible, you can use the package without TypeScript types. TypeScript will treat it as any other JavaScript code, and you won't get the benefits of type checking for that specific package.

  3. Contact the Author: If the package is actively maintained, you can consider reaching out to the package author and ask them to provide TypeScript type definitions or publish them on DefinitelyTyped.

Remember that TypeScript types are not always available for every JavaScript package, especially for less popular or niche libraries.