From 6883ea63666157e4e1ca91850459419405398c60 Mon Sep 17 00:00:00 2001 From: Maksim Ivanov Date: Thu, 12 Sep 2024 18:26:55 +0300 Subject: [PATCH] fix(kit): add overload for `TuiFilterByInputPipe` (#8912) --- .../pipes/filter-by-input/examples/2/index.ts | 15 ++++++++------- .../pipes/filter-by-input/filter-by-input.pipe.ts | 9 +-------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/projects/demo/src/modules/pipes/filter-by-input/examples/2/index.ts b/projects/demo/src/modules/pipes/filter-by-input/examples/2/index.ts index 6d03e77d1c8e..31ecb2f80dd4 100644 --- a/projects/demo/src/modules/pipes/filter-by-input/examples/2/index.ts +++ b/projects/demo/src/modules/pipes/filter-by-input/examples/2/index.ts @@ -2,6 +2,7 @@ import {Component, inject} from '@angular/core'; import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms'; import {changeDetection} from '@demo/emulate/change-detection'; import {encapsulation} from '@demo/emulate/encapsulation'; +import type {TuiStringMatcher} from '@taiga-ui/cdk'; import { TuiDataListWrapper, TuiFilterByInputPipe, @@ -27,7 +28,7 @@ interface User { encapsulation, changeDetection, }) -export default class Example { +export default class Example { protected readonly items = inject('Pythons' as any); protected readonly users = [ @@ -36,18 +37,18 @@ export default class Example { {id: 3, name: 'Graham Chapman'}, {id: 4, name: 'Michael Palin'}, {id: 5, name: 'Terry Gilliam'}, - ]; + ] as unknown as readonly T[]; protected readonly form = new FormGroup({ - user: new FormControl(null), - user2: new FormControl(null), + user: new FormControl(null), + user2: new FormControl(null), }); - protected readonly stringify = ({name}: User): string => name; + protected readonly stringify = ({name}: T): string => name; protected readonly matcherString = (name: string, search: string): boolean => - name.split(' ').pop()!.toLowerCase().startsWith(search.toLowerCase()); + name.split(' ').pop()?.toLowerCase().startsWith(search.toLowerCase()) ?? false; - protected readonly matcherUser = (user: User, search: string): boolean => + protected readonly matcherUser: TuiStringMatcher = (user, search): boolean => user.name.toLowerCase().startsWith(search.toLowerCase()); } diff --git a/projects/kit/pipes/filter-by-input/filter-by-input.pipe.ts b/projects/kit/pipes/filter-by-input/filter-by-input.pipe.ts index f162c145fafa..c53e6b62ed39 100644 --- a/projects/kit/pipes/filter-by-input/filter-by-input.pipe.ts +++ b/projects/kit/pipes/filter-by-input/filter-by-input.pipe.ts @@ -7,13 +7,6 @@ import {TUI_DATA_LIST_HOST} from '@taiga-ui/core/components/data-list'; import {TuiTextfieldComponent} from '@taiga-ui/core/components/textfield'; import {tuiIsFlat} from '@taiga-ui/kit/utils'; -type TuiArrayElement = - A extends ReadonlyArray - ? A extends ReadonlyArray> - ? G - : T - : never; - // TODO: Consider replacing TuiTextfieldComponent with proper token once we refactor textfields @Pipe({ standalone: true, @@ -25,7 +18,7 @@ export class TuiFilterByInputPipe implements PipeTransform { private readonly textfield = inject(TuiTextfieldComponent, {optional: true}); private readonly host = inject(TUI_DATA_LIST_HOST); - public transform(items: T, matcher?: TuiStringMatcher>): T; + public transform(items: readonly T[], matcher?: TuiStringMatcher): readonly T[]; public transform( items: ReadonlyArray | readonly T[] | null, matcher: TuiStringMatcher = TUI_DEFAULT_MATCHER,