Skip to content

Commit 95f8b73

Browse files
committed
feat: improve type of xyEnsureGrowingX and xyGrowingX
1 parent 91fb808 commit 95f8b73

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/xy/xyEnsureGrowingX.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { DataXY } from 'cheminfo-types';
1+
import type { DataXY, NumberArray } from 'cheminfo-types';
22

33
import { xIsMonotonic } from '../x/index.ts';
44

@@ -8,7 +8,9 @@ import { xyCheck } from './xyCheck.ts';
88
* Filters x,y values to allow strictly growing values in x-axis.
99
* @param data - Object that contains property x (an ordered increasing array) and y (an array).
1010
*/
11-
export function xyEnsureGrowingX(data: DataXY): DataXY {
11+
export function xyEnsureGrowingX<DataType extends NumberArray = NumberArray>(
12+
data: DataXY<DataType>,
13+
): DataXY<DataType | number[]> {
1214
xyCheck(data);
1315
if (xIsMonotonic(data.x) === 1) return data;
1416
const x = Array.from(data.x);

src/xy/xyGrowingX.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import type { DataXY } from 'cheminfo-types';
1+
import type { DataXY, NumberArray } from 'cheminfo-types';
22

33
/**
44
* Order object of array, x has to be monotone. Ensure x is growing
55
* @param data - Object of kind {x:[], y:[]}.
66
*/
7-
export function xyGrowingX(data: DataXY): DataXY {
7+
export function xyGrowingX<DataType extends NumberArray = NumberArray>(
8+
data: DataXY<DataType>,
9+
): DataXY<DataType> {
810
const { x, y } = data;
911

1012
if (x.length !== y.length) {
@@ -14,7 +16,7 @@ export function xyGrowingX(data: DataXY): DataXY {
1416
if (x.length < 2 || x[0] < (x.at(-1) as number)) return data;
1517

1618
return {
17-
x: x.toReversed(),
18-
y: y.toReversed(),
19+
x: x.toReversed() as DataType,
20+
y: y.toReversed() as DataType,
1921
};
2022
}

0 commit comments

Comments
 (0)