question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use new types contained within Units in some operations

See original GitHub issue

I 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 BigFractions will be converted to BigNumbers, 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:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
josdejongcommented, Jul 13, 2020

Published now in v7.1.0 🎉

0reactions
josdejongcommented, Jul 13, 2020

Fixed via #1903

Read more comments on GitHub >

github_iconTop Results From Across the Web

BatchWriteItem - Amazon DynamoDB - AWS Documentation
The BatchWriteItem operation puts or deletes multiple items in one or more tables. A single call to BatchWriteItem can transmit up to 16MB...
Read more >
RFC 6241: Network Configuration Protocol (NETCONF)
The NETCONF protocol operations are realized as remote procedure calls (RPCs). ... Global configuration attributes can be changed during any authorized ...
Read more >
What is Operational Risk? Definition from SearchCompliance
Operational risk is a type of business risk that is caused by flawed or failed processes, policies, systems or events.
Read more >
systemctl - Freedesktop.org
List units that systemd currently has in memory. This includes units that are either referenced directly or through a dependency, units that are...
Read more >
Transient fault handling - Azure - Microsoft Learn
Use the type of the exception and any data it contains, or the error codes and messages returned from the service, to optimize...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found