Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear documentation for calling functions with fractions #2645

Closed
wouterbeek opened this issue Aug 10, 2022 · 3 comments
Closed

Unclear documentation for calling functions with fractions #2645

wouterbeek opened this issue Aug 10, 2022 · 3 comments

Comments

@wouterbeek
Copy link

The documentation on https://mathjs.org/docs/datatypes/fractions.html states that "[m]ost functions will determine the type of output from the type of input: [...], a Fraction as input returns a Fraction as output".

I specifically cannot get this to work for fractions. For me, every function that takes only Fraction parameters returns an object of type MathType. This object cannot be stored in a Fraction object without an explicit cast (one per function call) and it cannot be returned by a function that has return type Fraction.

Could the documentation be wrong here? It is required to do an explicit cast after every function call involving fractions?

Here is my example code:

import { all, ConfigOptions, create, Fraction } from 'mathjs'
const config: ConfigOptions = {
  number: 'Fraction',
}
const math = create(all, config)

async function run() {
  const a: Fraction = math.fraction(1)
  const b: Fraction = math.fraction(60)
  const c: Fraction = math.divide(a, b) // <--- wrong type, returns 'MathType'
}
@wouterbeek wouterbeek changed the title Unclear documentation for calling functions with rations Unclear documentation for calling functions with fractions Aug 10, 2022
@josdejong
Copy link
Owner

I think you're hitting the issue that the TypeScript definitions are not up to date for Fraction for many functions, see #2582 (comment)

@wouterbeek
Copy link
Author

Ah, that's too bad. I'm closing this issue since it is a duplicate.

@josdejong
Copy link
Owner

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants