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 (#6107)
  • Loading branch information
splincode authored Nov 30, 2023
1 parent 9e765dd commit ee9d470
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 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
12 changes: 7 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,13 @@ 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.valueOf() - value.valueOf()) <
Math.abs(previous.valueOf() - value.valueOf())
? current
: previous,
new TuiTime(0, 0),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe(`InputTime`, () => {
control = new FormControl(new TuiTime(12, 30));
cleaner = false;
readOnly = false;
items: TuiTime[] | null = [];
items: TuiTime[] = [];
labelOutside = false;
size: TuiSizeL | TuiSizeS = `l`;
strict = false;
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 ee9d470

Please sign in to comment.