Skip to content

Constructor fails to recognize valid input #21

@FrozenKiwi

Description

@FrozenKiwi

We can make the constructor a lot more robust by removing the value instanceof Decimal type guard.

The problem with this guard is that you can get false negatives (esp if you end up with different versions of Decimal in your project, for whatever reason). This causes very difficult-to-trace issues where code will throw on valid inputs depending on where the source object was constructed.

The condition probably doesn't need to be quite so restrictive. What if it was replaced with duck-typing? (this could also help in dumping to/from json).

if (typeof value.s == 'number' && typeof value.e == 'number' ... etc )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions