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

fix: mode signature return types #3153

Merged
merged 11 commits into from
Feb 21, 2024
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,6 @@ Brooks Smith <[email protected]>
Alex Edgcomb <[email protected]>
S.Y. Lee <[email protected]>
Hudsxn <[email protected]>
Rich Martinez <[email protected]>

# Generated by tools/update-authors.js
31 changes: 31 additions & 0 deletions test/typescript-tests/testTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2542,3 +2542,34 @@ Match types of exact positional arguments.
expectTypeOf(node3.items[0]).toMatchTypeOf<ConstantNode>()
expectTypeOf(node3.items[1]).toMatchTypeOf<SymbolNode>()
}

/**
* mode Return Types
*/
{
const math = create(all, {})
const a = math.mode<number>([1, 2, 3])
expectTypeOf(a).toMatchTypeOf<number[]>()
assert.deepStrictEqual(a, [1, 2, 3])

const b = math.mode<number>([
[1, 2],
[2, 2],
[3, 5]
])
expectTypeOf(b).toMatchTypeOf<number[]>()
assert.deepStrictEqual(b, [2])

const c = math.mode<number>(1, 2, 2, 2, 3, 5)
expectTypeOf(c).toMatchTypeOf<number[]>()
assert.deepStrictEqual(c, [2])

const d = math.mode(1, 2, 2, 2, 3, 5)
expectTypeOf(d).toMatchTypeOf<number[]>()
assert.deepStrictEqual(d, [2])

const mathCollection = math.concat([1, 2, 3], [1], [4, 5])
const e = math.mode(mathCollection)
expectTypeOf(e).toMatchTypeOf<MathScalarType[]>()
assert.deepStrictEqual(e, [1])
}
10 changes: 5 additions & 5 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2760,22 +2760,22 @@ export interface MathJsInstance extends MathJsFactory {
* @param args Multiple scalar values
* @returns The mode of all values
*/
mode<T extends MathScalarType>(...args: T[]): T
mode<T extends MathScalarType>(...args: T[]): T[]
/**
* @param args Multiple scalar values
* @returns The mode of all values
*/
mode(...args: MathScalarType[]): MathScalarType
mode(...args: MathScalarType[]): MathScalarType[]
/**
* @param A A single matrix
* @returns The median value
* @returns The mode value
*/
mode<T extends MathScalarType>(A: T[] | T[][]): T
mode<T extends MathScalarType>(A: T[] | T[][]): T[]
/**
* @param A A single matrix
* @returns The mode of all values
*/
mode(A: MathCollection): MathScalarType
mode(A: MathCollection): MathScalarType[]

/**
* Compute the product of a matrix or a list with values. In case of a
Expand Down