monet/monet.js

issues when using monet in typescript

albertywu opened this issue · 2 comments

First of all, thanks for the wonderful library! I noticed an issue when using monet in typescript, that is preventing me from adopting the library on some of my projects.

If you notice the red squiggles below, that is typescript complaining that the type of x is {}. So it's unable to do multiplication:

screen shot 2018-01-24 at 8 26 29 pm

Is there something obvious I'm missing, or should the type definitions files be updated to handle this case? It seems like a fairly common usage pattern for Maybe / Some / None.

Thanks :)

try telling TypeScript the exact value of type parameter in constructors - use None<number>()

In the second case, you can take another approach instead, and annotate the getMaybe function:

const getMaybe = (): Maybe<number>  => Math.random() > .5 ? Some(1) : None();

Perfect - thank you!