1
1
import { tsUnionOf } from "../src/utils" ;
2
+ import { tsIntersectionOf } from "../src/utils" ;
2
3
3
4
describe ( "utils" , ( ) => {
4
5
describe ( "tsUnionOf" , ( ) => {
@@ -18,4 +19,26 @@ describe("utils", () => {
18
19
return expect ( tsUnionOf ( ...[ 0 , true , "string" , '"hello"' ] ) ) . toBe ( '0 | true | string | "hello"' ) ;
19
20
} ) ;
20
21
} ) ;
22
+
23
+ describe ( "tsIntersectionOf" , ( ) => {
24
+ const tests : [ string , string [ ] , string ] [ ] = [
25
+ [ "identity for single type" , [ "string" ] , "string" ] ,
26
+ [ "basic intersection" , [ "string" , "number" ] , "string & number" ] ,
27
+ [ "filter out unknown" , [ "string" , "number" , "unknown" ] , "string & number" ] ,
28
+ [ "identity for unknown type" , [ "unknown" ] , "unknown" ] ,
29
+ [ "unknown for no types passed" , [ ] , "unknown" ] ,
30
+ [ "parentheses around types with union" , [ "4" , `string | number` ] , "4 & (string | number)" ] ,
31
+ [
32
+ "parentheses around types with intersection" ,
33
+ [ "{ red: string }" , "{ blue: string } & { green: string }" ] ,
34
+ "{ red: string } & ({ blue: string } & { green: string })" ,
35
+ ] ,
36
+ ] ;
37
+
38
+ tests . forEach ( ( [ name , input , output ] ) => {
39
+ test ( name , ( ) => {
40
+ expect ( tsIntersectionOf ( ...input ) ) . toBe ( output ) ;
41
+ } ) ;
42
+ } ) ;
43
+ } ) ;
21
44
} ) ;
0 commit comments