File tree 2 files changed +24
-2
lines changed
2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ export namespace Signal {
44
44
#brand( ) { }
45
45
46
46
static {
47
- isState = ( s ) => #brand in s ;
47
+ isState = ( s ) => typeof s === 'object' && #brand in s ;
48
48
}
49
49
50
50
constructor ( initialValue : T , options : Signal . Options < T > = { } ) {
@@ -84,7 +84,7 @@ export namespace Signal {
84
84
#brand( ) { }
85
85
// eslint-disable-next-line @typescript-eslint/no-explicit-any
86
86
static {
87
- isComputed = ( c : any ) => #brand in c ;
87
+ isComputed = ( c : any ) => typeof c === 'object' && #brand in c ;
88
88
}
89
89
90
90
// Create a Signal which evaluates to the value returned by the callback.
Original file line number Diff line number Diff line change
1
+ import { describe , expect , it } from 'vitest' ;
2
+ import { Signal } from '../../src/wrapper.js' ;
3
+
4
+ describe ( 'Guards' , ( ) => {
5
+ it ( 'should work with Signals' , ( ) => {
6
+ const state = new Signal . State ( 1 ) ;
7
+ const computed = new Signal . Computed ( ( ) => state . get ( ) * 2 ) ;
8
+ expect ( Signal . isState ( state ) ) . toBe ( true ) ;
9
+ expect ( Signal . isComputed ( state ) ) . toBe ( false ) ;
10
+
11
+ expect ( Signal . isState ( computed ) ) . toBe ( false ) ;
12
+ expect ( Signal . isComputed ( computed ) ) . toBe ( true ) ;
13
+ } ) ;
14
+
15
+ it ( "shouldn't error with values" , ( ) => {
16
+ expect ( Signal . isState ( 1 ) ) . toBe ( false ) ;
17
+ expect ( Signal . isComputed ( 2 ) ) . toBe ( false ) ;
18
+
19
+ expect ( Signal . isState ( { } ) ) . toBe ( false ) ;
20
+ expect ( Signal . isComputed ( { } ) ) . toBe ( false ) ;
21
+ } ) ;
22
+ } ) ;
You can’t perform that action at this time.
0 commit comments