Type of the non-final entries of an Array `.value` when precision is applied in constructor
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 58
- Forks
- 12
- Avg merge
- 2h 35m
- Merged PRs (30d)
- 2
Description
Splitting off from #141 , where the suggestion was that if fractionDigits is supplied as an option in the constructor, we need to make a decision about the types of the entries in the store .value array, in particular the non-final ones. Example:
let a = new Amount([5, 11.1], { unit: "foot-and-inch", fractionDigits: 0 })
Should a.value be [5, "1.1e+1"] or ["5e+0", "1.1e+1"]?
Storing only the last entry as a decimal-digit string matches the rule that an input numeric value gets stringified when precision is applied to it. The earlier entries are required* to be integers, so they carry no precision information. Following the "stop coercing things" philosophy, an input Number stays a Number. The result is the mixed array [5, "1.1e+1"].
(* This argument assumes that the only units we support in sequence units are always integer multiples of one another, starting from the smallest to the biggest. That should be safe to assume but perhaps there are counterexamples.)
On the other hand, the "precision specified --> stringify" principle could be understood as applying to each component of the argument, even if it requires us to put an integral Number in quotes. Moreover, there may be something to be said for favoring uniform arrays. Thus, we ought to store ["5e+0", "1.1e+1"].
We need to decide which principles we want to stick to in the context of sequence units and make a decision. Presumably the same logic ought to apply to .convertTo, too.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the discussion in #141 and compare the constructor's precision behavior with the proposed .value representations for sequence units. Then examine how .convertTo should follow the same rule. Done means the project has decided and documented whether non-final entries remain Numbers or are stringified.
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
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100