josdejong / mathjs

An extensive math library for JavaScript and Node.js
https://mathjs.org
Apache License 2.0
14.43k stars 1.24k forks source link

fraction methods are not typed #3317

Open yukulele opened 1 week ago

yukulele commented 1 week ago

Describe the bug Fraction type only exposes s, n add d properties

mathjs/types/index.d.ts:4018:

export interface Fraction {
  s: number
  n: number
  d: number
}

so we can't use methods

To Reproduce

math.fraction('1.5').toFraction() // "3/2"
> tsc
error TS2339: Property 'toFraction' does not exist on type 'Fraction'.

9 math.fraction('1.5').toFraction()
                       ~~~~~~~~~~
josdejong commented 1 week ago

Thanks for reporting, we should improve the TypeScript definitions. Ideally, we can import and use type definitions from Fraction.js.

Who can help fix the TypeScript definitions of fractions?

yukulele commented 1 week ago

I think you might need to update the fraction.js version first, which is out outdated.

josdejong commented 1 week ago

Yes, that is addressed via https://github.com/josdejong/mathjs/pull/3283, it is a breaking change planned for v14.