issues when using monet in typescript
albertywu opened this issue · 2 comments
albertywu commented
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:
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.
ulfryk commented
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();
albertywu commented
Perfect - thank you!