From 957255f5d905abf1a9cc6da874ca0c316ca8cd32 Mon Sep 17 00:00:00 2001 From: splincode Date: Mon, 9 Sep 2024 14:09:08 +0300 Subject: [PATCH 1/2] fix(kit): add overload for `TuiFilterByInputPipe` --- .../src/modules/pipes/filter-by-input/examples/2/index.ts | 7 ++++--- projects/kit/pipes/filter-by-input/filter-by-input.pipe.ts | 1 + 2 files changed, 5 insertions(+), 3 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..0fe209f4b9e4 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,7 +37,7 @@ export default class Example { {id: 3, name: 'Graham Chapman'}, {id: 4, name: 'Michael Palin'}, {id: 5, name: 'Terry Gilliam'}, - ]; + ] as T[]; // only template compile check protected readonly form = new FormGroup({ user: new FormControl(null), @@ -48,6 +49,6 @@ export default class Example { protected readonly matcherString = (name: string, search: string): boolean => name.split(' ').pop()!.toLowerCase().startsWith(search.toLowerCase()); - 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..7e9da610baa0 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 @@ -25,6 +25,7 @@ export class TuiFilterByInputPipe implements PipeTransform { private readonly textfield = inject(TuiTextfieldComponent, {optional: true}); private readonly host = inject(TUI_DATA_LIST_HOST); + public transform(items: readonly T[], matcher?: TuiStringMatcher): readonly T[]; public transform(items: T, matcher?: TuiStringMatcher>): T; public transform( items: ReadonlyArray | readonly T[] | null, From edf93d6069626e0e1547ac9ea240d96a34ce2a69 Mon Sep 17 00:00:00 2001 From: splincode Date: Mon, 9 Sep 2024 15:20:41 +0300 Subject: [PATCH 2/2] chore: comments --- .../pipes/filter-by-input/examples/2/index.ts | 12 ++++++------ .../pipes/filter-by-input/filter-by-input.pipe.ts | 8 -------- 2 files changed, 6 insertions(+), 14 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 0fe209f4b9e4..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 @@ -28,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 = [ @@ -37,17 +37,17 @@ export default class Example { {id: 3, name: 'Graham Chapman'}, {id: 4, name: 'Michael Palin'}, {id: 5, name: 'Terry Gilliam'}, - ] as T[]; // only template compile check + ] 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: 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 7e9da610baa0..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, @@ -26,7 +19,6 @@ export class TuiFilterByInputPipe implements PipeTransform { private readonly host = inject(TUI_DATA_LIST_HOST); public transform(items: readonly T[], matcher?: TuiStringMatcher): readonly T[]; - public transform(items: T, matcher?: TuiStringMatcher>): T; public transform( items: ReadonlyArray | readonly T[] | null, matcher: TuiStringMatcher = TUI_DEFAULT_MATCHER,