Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access these functions from DefinitelyTyped in typescript?

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?

like image 280
Jake Sandler Avatar asked Oct 30 '25 06:10

Jake Sandler


1 Answers

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

like image 110
Amrit Avatar answered Nov 01 '25 19:11

Amrit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!