From c1380417841088379a210235524db61d61268415 Mon Sep 17 00:00:00 2001 From: Pascal Weyrich Date: Mon, 14 Apr 2025 12:35:17 +0200 Subject: [PATCH] refactor: improve signature of l10n-translate-pipe for better type inference In applications using "strictTemplates" angular compiler option, the signature of the translate pipe is problematic: Regardless of the passed key, the return type always includes `null`. In reality however, unless `null` or an empty string is passed, the pipe actually always returns a string. This adds some overload signatures to align with the pipes actual behaviour. --- projects/angular-l10n/src/lib/pipes/l10n-translate.pipe.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/angular-l10n/src/lib/pipes/l10n-translate.pipe.ts b/projects/angular-l10n/src/lib/pipes/l10n-translate.pipe.ts index f771c3c..bef3ebf 100644 --- a/projects/angular-l10n/src/lib/pipes/l10n-translate.pipe.ts +++ b/projects/angular-l10n/src/lib/pipes/l10n-translate.pipe.ts @@ -12,6 +12,9 @@ export class L10nTranslatePipe implements PipeTransform { constructor(protected translation: L10nTranslationService) { } + public transform(key: null, language: string, params?: any): null; + public transform(key: "", language: string, params?: any): null; + public transform(key: string, language: string, params?: any): string; public transform(key: any, language: string, params?: any): string | null { if (key == null || key === '') return null;