From 19d658401418636045ed67aa270c351ac47a254f Mon Sep 17 00:00:00 2001 From: lukasss88 Date: Sat, 15 Nov 2025 17:40:53 +0100 Subject: [PATCH 1/2] feat(10): initial setup --- .../src/app/wrapper-utils.pipe.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 apps/angular/10-utility-wrapper-pipe/src/app/wrapper-utils.pipe.ts diff --git a/apps/angular/10-utility-wrapper-pipe/src/app/wrapper-utils.pipe.ts b/apps/angular/10-utility-wrapper-pipe/src/app/wrapper-utils.pipe.ts new file mode 100644 index 000000000..de9bee288 --- /dev/null +++ b/apps/angular/10-utility-wrapper-pipe/src/app/wrapper-utils.pipe.ts @@ -0,0 +1,10 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'wrappFn', +}) +export class WrapperUtilsPipe implements PipeTransform { + transform(value: any, ...args: any[]) { + throw new Error('Method not implemented.'); + } +} From 687fbce7e88b470eff3a3f6821a43ee71f9e533e Mon Sep 17 00:00:00 2001 From: lukasss88 Date: Sun, 16 Nov 2025 10:46:51 +0100 Subject: [PATCH 2/2] feat(10): solution --- .../src/app/app.component.ts | 12 +++++------- .../10-utility-wrapper-pipe/src/app/person.utils.ts | 13 +++++++++++++ .../src/app/wrapper-utils.pipe.ts | 13 +++++++++++-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/apps/angular/10-utility-wrapper-pipe/src/app/app.component.ts b/apps/angular/10-utility-wrapper-pipe/src/app/app.component.ts index 9a8156a5f..82be78cd5 100644 --- a/apps/angular/10-utility-wrapper-pipe/src/app/app.component.ts +++ b/apps/angular/10-utility-wrapper-pipe/src/app/app.component.ts @@ -1,8 +1,9 @@ import { Component } from '@angular/core'; -import { PersonUtils } from './person.utils'; +import { WrapperUtilsPipe } from './wrapper-utils.pipe'; @Component({ selector: 'app-root', + imports: [WrapperUtilsPipe], template: ` @for (activity of activities; track activity.name) { {{ activity.name }} : @@ -12,8 +13,9 @@ import { PersonUtils } from './person.utils'; let index = $index; let isFirst = $first ) { - {{ showName(person.name, index) }} - {{ isAllowed(person.age, isFirst, activity.minimumAge) }} + {{ 'showName' | wrappFn: person.name : index }} + {{ 'isAllowed' | wrappFn: person.age : isFirst : activity.minimumAge }} +
} } `, @@ -30,8 +32,4 @@ export class AppComponent { { name: 'hiking', minimumAge: 25 }, { name: 'dancing', minimumAge: 1 }, ]; - - showName = PersonUtils.showName; - - isAllowed = PersonUtils.isAllowed; } diff --git a/apps/angular/10-utility-wrapper-pipe/src/app/person.utils.ts b/apps/angular/10-utility-wrapper-pipe/src/app/person.utils.ts index 66451dad4..35e1313d2 100644 --- a/apps/angular/10-utility-wrapper-pipe/src/app/person.utils.ts +++ b/apps/angular/10-utility-wrapper-pipe/src/app/person.utils.ts @@ -15,3 +15,16 @@ export const PersonUtils = { showName, isAllowed, }; + +export type PersonUtils = typeof PersonUtils; + +export type PersonUtilsFnKey = { + [K in keyof PersonUtils]: PersonUtils[K] extends (...args: any[]) => any + ? K + : never; +}[keyof PersonUtils]; + +export type PersonUtilParams = + PersonUtils[K] extends (...args: infer A) => any ? A : never; +export type PersonUtilReturnType = + PersonUtils[K] extends (...args: any[]) => infer R ? R : never; diff --git a/apps/angular/10-utility-wrapper-pipe/src/app/wrapper-utils.pipe.ts b/apps/angular/10-utility-wrapper-pipe/src/app/wrapper-utils.pipe.ts index de9bee288..505f4157f 100644 --- a/apps/angular/10-utility-wrapper-pipe/src/app/wrapper-utils.pipe.ts +++ b/apps/angular/10-utility-wrapper-pipe/src/app/wrapper-utils.pipe.ts @@ -1,10 +1,19 @@ import { Pipe, PipeTransform } from '@angular/core'; +import { + PersonUtilParams, + PersonUtilReturnType, + PersonUtils, + PersonUtilsFnKey, +} from './person.utils'; @Pipe({ name: 'wrappFn', }) export class WrapperUtilsPipe implements PipeTransform { - transform(value: any, ...args: any[]) { - throw new Error('Method not implemented.'); + transform( + fn: T, + ...args: PersonUtilParams + ): PersonUtilReturnType { + return (PersonUtils[fn] as Function)(...args); } }