refactor(common): log a warning when a KeyValuePipe receives a signal

Add signal warning for `KeyValuePipe` and consolidates the `invalidPipeArgumentError` function into a `utils`
This commit is contained in:
SkyZeroZx
2026-02-20 17:21:44 -05:00
committed by Jessica Janiuk
parent 957466d02a
commit 97ed3d9e85
10 changed files with 25 additions and 12 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ import {
} from '@angular/core';
import type {Observable, Subscribable, Unsubscribable} from 'rxjs';
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
import {invalidPipeArgumentError} from './utils';
interface SubscriptionStrategy {
createSubscription(
@@ -8,7 +8,7 @@
import {Pipe, PipeTransform, Type} from '@angular/core';
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
import {invalidPipeArgumentError} from './utils';
/**
* Transforms text to all lower case.
+1 -1
View File
@@ -11,7 +11,7 @@ import {Inject, InjectionToken, LOCALE_ID, Optional, Pipe, PipeTransform} from '
import {formatDate} from '../i18n/format_date';
import {DatePipeConfig, DEFAULT_DATE_FORMAT} from './date_pipe_config';
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
import {invalidPipeArgumentError} from './utils';
/**
* Optionally-provided default timezone to use for all instances of `DatePipe` (such as `'+0430'`).
@@ -10,7 +10,7 @@ import {Pipe, PipeTransform} from '@angular/core';
import {getPluralCategory, NgLocalization} from '../i18n/localization';
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
import {invalidPipeArgumentError} from './utils';
const _INTERPOLATION_REGEXP: RegExp = /#/g;
@@ -8,7 +8,7 @@
import {Pipe, PipeTransform} from '@angular/core';
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
import {invalidPipeArgumentError} from './utils';
/**
* @ngModule CommonModule
+3 -4
View File
@@ -6,7 +6,8 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {isSignal, Pipe, PipeTransform} from '@angular/core';
import {Pipe, PipeTransform} from '@angular/core';
import {warnIfSignal} from './utils';
/**
* @ngModule CommonModule
@@ -34,9 +35,7 @@ export class JsonPipe implements PipeTransform {
* @param value A value of any type to convert into a JSON-format string.
*/
transform(value: any): string {
if (ngDevMode && isSignal(value)) {
console.warn(`The JsonPipe does not unwrap signals. Received a signal with value:`, value());
}
ngDevMode && warnIfSignal('JsonPipe', value);
return JSON.stringify(value, null, 2);
}
@@ -14,6 +14,7 @@ import {
Pipe,
PipeTransform,
} from '@angular/core';
import {warnIfSignal} from './utils';
function makeKeyValuePair<K, V>(key: K, value: V): KeyValue<K, V> {
return {key: key, value: value};
@@ -109,6 +110,8 @@ export class KeyValuePipe implements PipeTransform {
input: undefined | null | {[key: string]: V; [key: number]: V} | ReadonlyMap<K, V>,
compareFn: ((a: KeyValue<K, V>, b: KeyValue<K, V>) => number) | null = defaultComparator,
): Array<KeyValue<K, V>> | null {
ngDevMode && warnIfSignal('KeyValuePipe', input);
if (!input || (!(input instanceof Map) && typeof input !== 'object')) {
return null;
}
+1 -1
View File
@@ -18,7 +18,7 @@ import {
import {formatCurrency, formatNumber, formatPercent} from '../i18n/format_number';
import {getCurrencySymbol} from '../i18n/locale_data_api';
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
import {invalidPipeArgumentError} from './utils';
import {RuntimeErrorCode} from '../errors';
/**
+1 -1
View File
@@ -8,7 +8,7 @@
import {Pipe, PipeTransform} from '@angular/core';
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
import {invalidPipeArgumentError} from './utils';
/**
* @ngModule CommonModule
@@ -6,7 +6,12 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {Type, ɵRuntimeError as RuntimeError, ɵstringify as stringify} from '@angular/core';
import {
Type,
ɵRuntimeError as RuntimeError,
ɵstringify as stringify,
isSignal,
} from '@angular/core';
import {RuntimeErrorCode} from '../errors';
@@ -16,3 +21,9 @@ export function invalidPipeArgumentError(type: Type<any>, value: Object) {
ngDevMode && `InvalidPipeArgument: '${value}' for pipe '${stringify(type)}'`,
);
}
export function warnIfSignal(pipeName: string, value: unknown): void {
if (isSignal(value)) {
console.warn(`The ${pipeName} does not unwrap signals. Received a signal with value:`, value());
}
}