I am trying to create an Angular2 app that works with money amounts. I am trying to use dinero.js to represent money values, but I am having a hard time using certain features in Typescript.
As the instructions suggested, I installed the DefinitelyTyped mappings for dinero.js using this command
npm install @types/dinero.js --save
The type mappings for this library are declared here.
I import the library into my code like this:
import * as Dinero from 'dinero.js';
This allows me to use the factory function Dinero. The problem is, that declaration lists some functions (namely maximum and minimum) that I want to use, but can't seem to get to.
If I try Dinero.maximum(...), I get:
"export 'maximum' (imported as 'Dinero') was not found in 'dinero.js'
If I try to import those functions directly:
import {maximum, minimum} from 'dinero.js';
and call by maximum(...), I get:
"export 'minimum' was not found in 'dinero.js'
How do I actually get to these functions?
you need to install these first :
npm install dinero.js --save
npm install @types/dinero.js --save
and then import and use it like this :
import Dinero from "dinero.js";
const some_currency: Dinery.Currency = 'USD'
const some_val: Dinero.Dinero = Dinero({amount: 0, currency: some_currency})
this is the stackblitz url which is working : https://stackblitz.com/edit/angular-ivy-spxp5x?file=src%2Fapp%2Fapp.component.ts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With