File tree Expand file tree Collapse file tree 3 files changed +42
-4
lines changed
Expand file tree Collapse file tree 3 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -838,7 +838,7 @@ export interface InputDecorator {
838838export function isDevMode(): boolean ;
839839
840840// @public
841- export function isSignal(value : Function ): value is Signal <unknown >;
841+ export function isSignal(value : unknown ): value is Signal <unknown >;
842842
843843// @public
844844export function isStandalone(type : Type <unknown >): boolean ;
Original file line number Diff line number Diff line change @@ -30,10 +30,12 @@ export type Signal<T> = (() => T)&{
3030} ;
3131
3232/**
33- * Checks if the given `value` function is a reactive `Signal`.
33+ * Checks if the given `value` is a reactive `Signal`.
34+ *
35+ * @developerPreview
3436 */
35- export function isSignal ( value : Function ) : value is Signal < unknown > {
36- return ( value as Signal < unknown > ) [ SIGNAL ] !== undefined ;
37+ export function isSignal ( value : unknown ) : value is Signal < unknown > {
38+ return typeof value === 'function' && ( value as Signal < unknown > ) [ SIGNAL ] !== undefined ;
3739}
3840
3941/**
Original file line number Diff line number Diff line change 1+ /**
2+ * @license
3+ * Copyright Google LLC All Rights Reserved.
4+ *
5+ * Use of this source code is governed by an MIT-style license that can be
6+ * found in the LICENSE file at https://angular.io/license
7+ */
8+
9+ import { computed , isSignal , signal } from '@angular/core/src/signals' ;
10+
11+ describe ( 'isSignal' , ( ) => {
12+ it ( 'should return true for writable signal' , ( ) => {
13+ const writableSignal = signal ( 'Angular' ) ;
14+ expect ( isSignal ( writableSignal ) ) . toBe ( true ) ;
15+ } ) ;
16+
17+ it ( 'should return true for readonly signal' , ( ) => {
18+ const readonlySignal = computed ( ( ) => 10 ) ;
19+ expect ( isSignal ( readonlySignal ) ) . toBe ( true ) ;
20+ } ) ;
21+
22+ it ( 'should return false for primitive' , ( ) => {
23+ const primitive = 0 ;
24+ expect ( isSignal ( primitive ) ) . toBe ( false ) ;
25+ } ) ;
26+
27+ it ( 'should return false for object' , ( ) => {
28+ const object = { name : 'Angular' } ;
29+ expect ( isSignal ( object ) ) . toBe ( false ) ;
30+ } ) ;
31+
32+ it ( 'should return false for function' , ( ) => {
33+ const fn = ( ) => { } ;
34+ expect ( isSignal ( fn ) ) . toBe ( false ) ;
35+ } ) ;
36+ } ) ;
You can’t perform that action at this time.
0 commit comments