tc39 / tc39/proposal-amount

Implication of polymorphic Amount to round-trip conversions

Open
#72 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
58
Forks
12
Avg merge
2h 35m
Merged PRs (30d)
2

Description

The current Amount proposal allows code such as

let amt1 = new Amount(2.5, { unit: "meter" });
let amt2 = amt1.withNumber(amt1.toNumber() * 2);

Without the helper functions withNumber and toNumber, the code is still possible, though a bit more verbose, perhaps worth moving into a helper function:

function doubleAmount(amt) {
    let number = Number.parseFloat(amt.toString());
    return new Amount(number * 2, { unit: amt.unit });
}

A concern here is that if developers are encouraged to use such a pattern, the resulting code is less efficient than if they had not converted to an Amount, if the Amount is stored as a decimal-like type.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with issue #72 and the current Amount proposal, focusing on the withNumber(), toNumber(), and helper-function examples. Determine whether round-trip conversions should be part of the proposal or avoided for efficiency when Amount uses a decimal-like representation. Done means the conversion concern has a documented design decision.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.