MikeMcl / decimal.js

An arbitrary-precision Decimal type for JavaScript
http://mikemcl.github.io/decimal.js
MIT License
6.35k stars 480 forks source link

Use type predicate on isDecimal #198

Closed dmarkow closed 2 years ago

dmarkow commented 2 years ago

Type Predicates help to narrow down types. Before this change:

const value: Decimal | string = "123";

if (Decimal.isDecimal(value)) {
  // do something
} else {
  // Typescript still thinks value can be a Decimal or string
}

After:

const value: Decimal | string = "123";

if (Decimal.isDecimal(value)) {
  // do something
} else {
  // Typescript now knows value is a string
}
MikeMcl commented 2 years ago

Yes, seems sensible. Thank you.

markogresak commented 2 years ago

@MikeMcl do you have a timeline to release a patch version on npm to include this type change?

MikeMcl commented 2 years ago

@markogresak

Published v10.4.0.

Thanks for the nudge.