francescov1 / mongoose-tsgen

A plug-n-play Typescript generator for Mongoose.
103 stars 24 forks source link

Usage with Decimal128 and number #67

Closed elie222 closed 3 years ago

elie222 commented 3 years ago

We just added this library and we use Decimal128 quite a lot. Till now these fields were fine accepting number but with this package added it's causing a problem as number isn't the same as Decimal128.

Any recommendations on how to handle this issue?

francescov1 commented 3 years ago

What exactly are the errors you're seeing?

This library does support Decimal128, but it just types it as number since Typescript doesn't have more accurate types, so if using number worked in the past then it should work with the library (if I'm understanding correctly). If you can provide a brief example that'd be super useful!

elie222 commented 3 years ago

Decided to move away from Decimal128 in the end to get around this issue.

Pretty sure Decimal128 wasn't being typed as number but was using the Mongo Decimal128 object which is different. So we were doing something like this to convert between the two:

Even though it was only a TS thing and number would have been fine in these cases (as it was before we were using types here).

Best, Eliezer

On Thu, Sep 23, 2021 at 1:15 AM, Francesco Virga < @.*** > wrote:

What exactly are the errors you're seeing?

This library does support Decimal128, but it just types it as number since Typescript doesn't have more accurate types, so if using number worked in the past then it should work with the library (if I'm understanding correctly). If you can provide a brief example that'd be super useful!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub ( https://github.com/francescov1/mongoose-tsgen/issues/67#issuecomment-925368590 ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAXSQX6R7ZSNKOUCTHQ4BRDUDJIPJANCNFSM5ESKH7RA ).

francescov1 commented 3 years ago

Ahh yes the Mongoose version of the doc gets typed as the Mongoose Decimal128 type, whereas the non-mongoose version uses number. Havent had many users need decimal128 so haven't seen much on how people use it. If you ever run into more issues with it let me know and I'd be happy to go deeper into the setup!