Skip to content

Improve quantileSeq typings #3198

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

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion test/typescript-tests/testTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2454,7 +2454,7 @@
}

/*
min/max return types
Statistics functions' return types
*/
{
const math = create(all, {})
Expand Down Expand Up @@ -2526,6 +2526,18 @@
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')])

Check failure on line 2539 in test/typescript-tests/testTypes.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Expected 2-3 arguments, but got 1.
).toMatchTypeOf<Unit>()
}

/*
Expand Down
15 changes: 14 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
Expand All @@ -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
Expand Down
Loading