From 49df88985eacb40e3de60b3cdbe201b2feb901db Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 16 May 2024 08:46:58 +0200 Subject: [PATCH 1/3] docs: document how to run tests for the type definitions --- README.md | 4 ++++ types/EXPLANATION.md | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 44c6e82f4..bb61a0b6a 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,10 @@ Then, the tests can be executed: npm test +To test the type definitions: + + npm run test:types + Additionally, the tests can be run on FireFox using [headless mode](https://developer.mozilla.org/en-US/Firefox/Headless_mode): npm run test:browser diff --git a/types/EXPLANATION.md b/types/EXPLANATION.md index 0bcb7b0ba..8f83778aa 100644 --- a/types/EXPLANATION.md +++ b/types/EXPLANATION.md @@ -1,6 +1,6 @@ # Mathjs TypeScript types -The code base of Mathjs is writting in JavaScript. The TypeScript definitions are maintained separately. +The code base of Mathjs is written in JavaScript. The TypeScript definitions are maintained separately. ## Library structure @@ -52,3 +52,15 @@ export const { // ... } : Record ``` + +## Testing the type definitions + +The types are defined in `types/index.d.ts`. + +The tests for the type definitions are located in `test/typescript-types/testTypes.ts`. + +To run the tests for the type definitions: + +``` +npm run test:types +``` From ffa3a2e20a2b2e4c3f0eda16c87c5ea6ad576e77 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Thu, 16 May 2024 07:47:13 +0100 Subject: [PATCH 2/3] Improve quantileSeq typings (#3198) * Improve quantileSeq typings * Add tests, revert comment changes * Fix type tests --- test/typescript-tests/testTypes.ts | 14 +++++++++++++- types/index.d.ts | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/test/typescript-tests/testTypes.ts b/test/typescript-tests/testTypes.ts index 1d4f31e09..caa78be3e 100644 --- a/test/typescript-tests/testTypes.ts +++ b/test/typescript-tests/testTypes.ts @@ -2454,7 +2454,7 @@ MathNode examples } /* -min/max return types +Statistics functions' return types */ { const math = create(all, {}) @@ -2526,6 +2526,18 @@ min/max return types expectTypeOf(math.median(123, math.bignumber('456'))).toMatchTypeOf< number | BigNumber | Fraction | Complex | Unit >() + + expectTypeOf(math.quantileSeq([1, 2, 3], 0.75)).toMatchTypeOf() + expectTypeOf(math.quantileSeq([[1, 2, 3]], 0.75)).toMatchTypeOf() + expectTypeOf( + math.quantileSeq([math.bignumber('123')], 0.75) + ).toMatchTypeOf() + expectTypeOf(math.quantileSeq(math.matrix([1, 2, 3]), 0.75)).toMatchTypeOf< + MathScalarType | MathArray + >() + expectTypeOf( + math.quantileSeq([math.unit('5cm'), math.unit('10cm')], 0.75) + ).toMatchTypeOf() } /* diff --git a/types/index.d.ts b/types/index.d.ts index 966ae1b76..a7e56e2e9 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2805,6 +2805,19 @@ export interface MathJsInstance extends MathJsFactory { */ prod(A: MathCollection): MathScalarType + /** + * @param A A single matrix + * @param probOrN prob is the order of the quantile, while N is the + * amount of evenly distributed steps of probabilities; only one of + * these options can be provided + * @param sorted =false is data sorted in ascending order + * @returns Quantile(s) + */ + quantileSeq( + A: T[] | T[][], + prob: number | BigNumber | MathArray, + sorted?: boolean + ): T /** * Compute the prob order quantile of a matrix or a list with values. * The sequence is sorted and the middle value is returned. Supported @@ -2823,7 +2836,7 @@ export interface MathJsInstance extends MathJsFactory { A: MathCollection, prob: number | BigNumber | MathArray, sorted?: boolean - ): number | BigNumber | Unit | MathArray + ): MathScalarType | MathArray /** * Compute the standard deviation of a matrix or a list with values. The From ab3b251368e6d8ee584a1ea8172afe01b7b4fbd7 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 16 May 2024 08:47:59 +0200 Subject: [PATCH 3/3] chore: update HISTORY.md --- HISTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.md b/HISTORY.md index 474ff57b1..6292ff2ce 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,7 @@ - Fix: serialization of Units without a value, see #1240. - Fix: outdated, incorrect documentation about the order of precedence for operator modulus `%`. See #3189. +- Fix: #3197 improve `quantileSeq` type definitions (#3198). Thanks @domdomegg. # 2024-04-24, 12.4.2