Merge branch 'refs/heads/develop' into v13

This commit is contained in:
Jos de Jong 2024-05-21 16:09:28 +02:00
commit f5755e71dc
5 changed files with 45 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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<number>()
expectTypeOf(math.quantileSeq([[1, 2, 3]], 0.75)).toMatchTypeOf<number>()
expectTypeOf(
math.quantileSeq([math.bignumber('123')], 0.75)
).toMatchTypeOf<BigNumber>()
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<Unit>()
}
/*

View File

@ -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<string, FactoryFunctionMap>
```
## 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
```

15
types/index.d.ts vendored
View File

@ -2807,6 +2807,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<T extends MathScalarType>(
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
@ -2825,7 +2838,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