@@ -77,4 +77,79 @@ Deno.test("isIntersectionOf<T>", async (t) => {
77
77
> ( true ) ;
78
78
}
79
79
} ) ;
80
+
81
+ await t . step ( "with symbol properties" , async ( t ) => {
82
+ const b = Symbol ( "b" ) ;
83
+ const objPreds = [
84
+ is . ObjectOf ( { a : is . Number } ) ,
85
+ is . ObjectOf ( { [ b ] : is . String } ) ,
86
+ ] as const ;
87
+ const mixPreds = [
88
+ is . Function ,
89
+ is . ObjectOf ( { [ b ] : is . String } ) ,
90
+ ] as const ;
91
+
92
+ await t . step ( "returns properly named predicate function" , async ( t ) => {
93
+ assertEquals ( typeof isIntersectionOf ( [ is . String ] ) , "function" ) ;
94
+ await assertSnapshot ( t , isIntersectionOf ( [ is . String ] ) . name ) ;
95
+ await assertSnapshot ( t , isIntersectionOf ( objPreds ) . name ) ;
96
+ await assertSnapshot ( t , isIntersectionOf ( mixPreds ) . name ) ;
97
+ } ) ;
98
+
99
+ await t . step ( "returns true on all of T" , ( ) => {
100
+ const f = Object . assign ( ( ) => void 0 , { [ b ] : "a" } ) ;
101
+ assertEquals ( isIntersectionOf ( [ is . String ] ) ( "a" ) , true ) ;
102
+ assertEquals ( isIntersectionOf ( objPreds ) ( { a : 0 , [ b ] : "a" } ) , true ) ;
103
+ assertEquals ( isIntersectionOf ( mixPreds ) ( f ) , true ) ;
104
+ } ) ;
105
+
106
+ await t . step ( "returns false on non of T" , ( ) => {
107
+ const f = Object . assign ( ( ) => void 0 , { [ b ] : "a" } ) ;
108
+ assertEquals ( isIntersectionOf ( objPreds ) ( "a" ) , false ) ;
109
+ assertEquals ( isIntersectionOf ( mixPreds ) ( { a : 0 , [ b ] : "a" } ) , false ) ;
110
+ assertEquals ( isIntersectionOf ( [ is . String ] ) ( f ) , false ) ;
111
+ } ) ;
112
+
113
+ await t . step ( "predicated type is correct" , ( ) => {
114
+ const a : unknown = undefined ;
115
+
116
+ if ( isIntersectionOf ( [ is . String ] ) ( a ) ) {
117
+ assertType < Equal < typeof a , string > > ( true ) ;
118
+ }
119
+
120
+ if ( isIntersectionOf ( objPreds ) ( a ) ) {
121
+ assertType < Equal < typeof a , { a : number } & { [ b ] : string } > > ( true ) ;
122
+ }
123
+
124
+ if ( isIntersectionOf ( mixPreds ) ( a ) ) {
125
+ assertType <
126
+ Equal <
127
+ typeof a ,
128
+ & ( ( ...args : unknown [ ] ) => unknown )
129
+ & { [ b ] : string }
130
+ >
131
+ > ( true ) ;
132
+ }
133
+ } ) ;
134
+
135
+ await t . step ( "predicated type is correct (#68)" , ( ) => {
136
+ const a : unknown = undefined ;
137
+ const pred = isIntersectionOf ( [
138
+ is . ObjectOf ( { id : is . String } ) ,
139
+ is . UnionOf ( [
140
+ is . ObjectOf ( { result : is . String } ) ,
141
+ is . ObjectOf ( { error : is . String } ) ,
142
+ ] ) ,
143
+ ] ) ;
144
+
145
+ if ( pred ( a ) ) {
146
+ assertType <
147
+ Equal <
148
+ typeof a ,
149
+ { id : string } & ( { result : string } | { error : string } )
150
+ >
151
+ > ( true ) ;
152
+ }
153
+ } ) ;
154
+ } ) ;
80
155
} ) ;
0 commit comments