Skip to content

Commit

Permalink
fix(kit): possible type error reduce of empty array with no initial v…
Browse files Browse the repository at this point in the history
…alue
  • Loading branch information
splincode committed Nov 27, 2023
1 parent b700101 commit ebedc9e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class TuiBarChartComponent {
private getMax(values: ReadonlyArray<readonly number[]>, collapsed: boolean): number {
return collapsed
? Math.max(
// eslint-disable-next-line no-restricted-syntax
...values.reduce((result, next) =>
result.map((value, index) => value + next[index]),
),
Expand Down
16 changes: 11 additions & 5 deletions projects/kit/components/input-time/input-time.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,17 @@ export class TuiInputTimeComponent
}

private findNearestTimeFromItems(value: TuiTime): TuiTime | null {
return this.items.reduce((previous, current) =>
Math.abs(current.toAbsoluteMilliseconds() - value.toAbsoluteMilliseconds()) <
Math.abs(previous.toAbsoluteMilliseconds() - value.toAbsoluteMilliseconds())
? current
: previous,
return this.items.reduce(
(previous, current) =>
Math.abs(
current.toAbsoluteMilliseconds() - value.toAbsoluteMilliseconds(),
) <
Math.abs(
previous.toAbsoluteMilliseconds() - value.toAbsoluteMilliseconds(),
)
? current
: previous,
new TuiTime(0, 0),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class TuiNativeMultiSelectGroupComponent<

onValueChange(selectedOptions: HTMLSelectElement['selectedOptions']): void {
const selected = Array.from(selectedOptions).map(option => option.index);
const flatItems = this.items?.reduce((acc, val) => acc.concat(val)) || [];
const flatItems = this.items?.reduce((acc, val) => acc.concat(val), []) || [];
const value = flatItems.filter((_, index) => selected.includes(index));

this.host.onSelectionChange(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class TuiNativeSelectGroupComponent<T> extends AbstractTuiNativeSelect<
}

onValueChange(index: number): void {
const flatItems = this.items?.reduce((acc, val) => acc.concat(val));
const flatItems = this.items?.reduce((acc, val) => acc.concat(val), []);

this.host.onValueChange(flatItems?.[index] || null);
}
Expand Down

0 comments on commit ebedc9e

Please sign in to comment.