scurker / currency.js

A javascript library for handling currencies

Home Page:https://currency.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What's the recommended way to import and use the TypeScript types?

NathanC opened this issue · comments

I'm currently doing:

import type currency from "currency.js";
import Currency from "currency.js"

Do I need to import type, or is there an alternative way to do it? I tried function f(arg: typeof currency)`, but that doesn't seem to work.

Do I just need to accept the currency object having a different name than the interface? I haven't seen many libraries use this kind of pattern (with two interfaces under the currency namespace in the module definition, and an interface named currency at the top-level of the module) so I'm not sure what the right way is to use them. Thanks!

Not sure if this fits your needs, but it works for me using an alias:

import currency, { default as Currency } from 'currency.js';

The type setup of this library is indeed abnormal to most others.

Huh, I think I was just doing something wrong earlier, not sure what it was. Now, when I do import currency from "currency.js I'm able to use currency both as the type, and use a static apply on it to construct a currency object. It also appears that new currency(5) works as well.

Not sure what behavior I was seeing before, closing.