Unable to use new types contained within Units in some operations
See original GitHub issueI have been attempting to implement a new type BigFraction
from fraction.js/bigfraction.js
. So far things have gone pretty well, except I’ve run into an issue with Units. Several of the definitions of operations are self referential for the Unit, Unit
signature, such as addScalar
below:
export const createAddScalar = /* #__PURE__ */ factory(name, dependencies, ({ typed }) => {
const addScalar = typed(name, {
'number, number': // ..,
'Complex, Complex': // ..,
'BigNumber, BigNumber': // ..,
'Fraction, Fraction': // ..,
'Unit, Unit': function (x, y) {
// ...
const res = x.clone()
res.value = addScalar(res.value, y.value) // <-- self reference
res.fixPrefix = false
return res
}
})
return addScalar
})
This factory defines an immutable list of signatures for the function addScalar
and thus when the Unit, Unit
signature calls the typed function, the only available signatures are the ones defined within this factory. It will not have access to any signatures merged into addScalar
by other factories later on.
E.g. when the following new factory is imported and the typed function is merged, the original Unit, Unit
signature of addScalar
does not have access to the new signatures.
export const createAddScalarBigFraction = factory("addScalar", dependencies, ({ typed }) => {
return typed("addScalar", {
"BigFraction, BigFraction": // ...,
"BigFraction, BigNumber": // ...,
"BigNumber, BigFraction": // ...
})
})
I have found as a work around that I can add an entry to typed.conversions
, and BigFraction
s will be converted to BigNumber
s, but this is not ideal as it requires that all unit math be done using BigNumbers
when BigFraction
may be preferable.
Is there any existing work around for this?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Published now in
v7.1.0
🎉Fixed via #1903