@@ -68,6 +68,11 @@ export interface ToSignalOptions<T> {
6868 * Equality comparisons are executed against the initial value if one is provided.
6969 */
7070 equal ?: ValueEqualityFn < T > ;
71+
72+ /**
73+ * A debug name for the signal. Used in Angular DevTools to identify the signal.
74+ */
75+ debugName ?: string ;
7176}
7277
7378// Base case: no options -> `undefined` in the result type.
@@ -149,12 +154,15 @@ export function toSignal<T, U = undefined>(
149154 let state : WritableSignal < State < T | U > > ;
150155 if ( options ?. requireSync ) {
151156 // Initially the signal is in a `NoValue` state.
152- state = signal ( { kind : StateKind . NoValue } , { equal} ) ;
157+ state = signal (
158+ { kind : StateKind . NoValue } ,
159+ { equal, ...( ngDevMode ? createDebugNameObject ( options ?. debugName , 'state' ) : undefined ) } ,
160+ ) ;
153161 } else {
154162 // If an initial value was passed, use it. Otherwise, use `undefined` as the initial value.
155163 state = signal < State < T | U > > (
156164 { kind : StateKind . Value , value : options ?. initialValue as U } ,
157- { equal} ,
165+ { equal, ... ( ngDevMode ? createDebugNameObject ( options ?. debugName , 'state' ) : undefined ) } ,
158166 ) ;
159167 }
160168
@@ -209,7 +217,10 @@ export function toSignal<T, U = undefined>(
209217 ) ;
210218 }
211219 } ,
212- { equal : options ?. equal } ,
220+ {
221+ equal : options ?. equal ,
222+ ...( ngDevMode ? createDebugNameObject ( options ?. debugName , 'source' ) : undefined ) ,
223+ } ,
213224 ) ;
214225}
215226
@@ -220,6 +231,18 @@ function makeToSignalEqual<T>(
220231 a . kind === StateKind . Value && b . kind === StateKind . Value && userEquality ( a . value , b . value ) ;
221232}
222233
234+ /**
235+ * Creates a debug name object for an internal toSignal signal.
236+ */
237+ function createDebugNameObject (
238+ toSignalDebugName : string | undefined ,
239+ internalSignalDebugName : string ,
240+ ) : { debugName ?: string } {
241+ return {
242+ debugName : `toSignal${ toSignalDebugName ? '#' + toSignalDebugName : '' } .${ internalSignalDebugName } ` ,
243+ } ;
244+ }
245+
223246const enum StateKind {
224247 NoValue ,
225248 Value ,
0 commit comments