Skip to content

Commit 9f147f4

Browse files
committed
fix: resolve TypeScript errors for x.at(-1) returning number | undefined
1 parent 4692d6b commit 9f147f4

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

src/xy/xyFilterX.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ export function xyFilterX(
4545
y: Array.from(y),
4646
};
4747
}
48-
const {
49-
from = x[0],
50-
to = x.at(-1),
51-
zones = [{ from, to }],
52-
exclusions = [],
53-
} = options;
48+
const from = options.from ?? x[0];
49+
const to = options.to ?? x.at(-1) ?? from;
50+
const { zones = [{ from, to }], exclusions = [] } = options;
5451

5552
const normalizedZones = zonesNormalize(zones, { from, to, exclusions });
5653

src/xy/xyReduce.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,9 @@ export function xyReduce(
6767
};
6868
}
6969
const { x, y } = data;
70-
const {
71-
from = x[0],
72-
to = x.at(-1),
73-
nbPoints = 4001,
74-
optimize = false,
75-
} = options;
70+
const from = options.from ?? x[0];
71+
const to = options.to ?? x.at(-1) ?? from;
72+
const { nbPoints = 4001, optimize = false } = options;
7673
let { zones = [] } = options;
7774

7875
zones = zonesNormalize(zones, { from, to });

src/xy/xyReduceNonContinuous.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export function xyReduceNonContinuous(
5151
};
5252
}
5353
const { x, y } = data;
54-
const { from = x[0], to = x.at(-1), maxApproximateNbPoints = 4001 } = options;
54+
const from = options.from ?? x[0];
55+
const to = options.to ?? x.at(-1) ?? from;
56+
const { maxApproximateNbPoints = 4001 } = options;
5557
let { zones = [] } = options;
5658

5759
zones = zonesNormalize(zones, { from, to });

0 commit comments

Comments
 (0)