@@ -1477,24 +1477,62 @@ Deno.test("isIntersectionOf<T>", async (t) => {
14771477 isObjectOf ( { a : isNumber } ) ,
14781478 isObjectOf ( { b : isString } ) ,
14791479 ] ) . name ,
1480+ "Should return `isObjectOf`, if all predicates that" ,
1481+ ) ;
1482+ await assertSnapshot (
1483+ t ,
1484+ isIntersectionOf ( [
1485+ isString ,
1486+ ] ) . name ,
1487+ "Should return as is, if there is only one predicate" ,
1488+ ) ;
1489+ await assertSnapshot (
1490+ t ,
1491+ isIntersectionOf ( [
1492+ isFunction ,
1493+ isObjectOf ( { b : isString } ) ,
1494+ ] ) . name ,
14801495 ) ;
14811496 } ) ;
14821497 await t . step ( "returns proper type predicate" , ( ) => {
1483- const preds = [
1498+ const objPreds = [
14841499 isObjectOf ( { a : isNumber } ) ,
14851500 isObjectOf ( { b : isString } ) ,
14861501 ] as const ;
1502+ const funcPreds = [
1503+ isFunction ,
1504+ isObjectOf ( { b : isString } ) ,
1505+ ] as const ;
14871506 const a : unknown = { a : 0 , b : "a" } ;
1488- if ( isIntersectionOf ( preds ) ( a ) ) {
1507+ if ( isIntersectionOf ( objPreds ) ( a ) ) {
14891508 assertType < Equal < typeof a , { a : number } & { b : string } > > ( true ) ;
14901509 }
1510+ if ( isIntersectionOf ( [ isString ] ) ( a ) ) {
1511+ assertType < Equal < typeof a , string > > ( true ) ;
1512+ }
1513+ if ( isIntersectionOf ( funcPreds ) ( a ) ) {
1514+ assertType <
1515+ Equal <
1516+ typeof a ,
1517+ & ( ( ...args : unknown [ ] ) => unknown )
1518+ & { b : string }
1519+ >
1520+ > ( true ) ;
1521+ }
14911522 } ) ;
14921523 await t . step ( "returns true on all of T" , ( ) => {
1493- const preds = [
1524+ const objPreds = [
14941525 isObjectOf ( { a : isNumber } ) ,
14951526 isObjectOf ( { b : isString } ) ,
14961527 ] as const ;
1497- assertEquals ( isIntersectionOf ( preds ) ( { a : 0 , b : "a" } ) , true ) ;
1528+ const funcPreds = [
1529+ isFunction ,
1530+ isObjectOf ( { b : isString } ) ,
1531+ ] as const ;
1532+ const f = Object . assign ( ( ) => void 0 , { b : "a" } ) ;
1533+ assertEquals ( isIntersectionOf ( objPreds ) ( { a : 0 , b : "a" } ) , true ) ;
1534+ assertEquals ( isIntersectionOf ( [ isString ] ) ( "a" ) , true ) ;
1535+ assertEquals ( isIntersectionOf ( funcPreds ) ( f ) , true ) ;
14981536 } ) ;
14991537 await t . step ( "returns false on non of T" , async ( t ) => {
15001538 const preds = [
@@ -1515,6 +1553,25 @@ Deno.test("isIntersectionOf<T>", async (t) => {
15151553 excludeExamples : [ "record" ] ,
15161554 } ) ;
15171555 } ) ;
1556+ await t . step ( "returns false on non of T with any predicates" , async ( t ) => {
1557+ const preds = [
1558+ isFunction ,
1559+ isObjectOf ( { b : isString } ) ,
1560+ ] as const ;
1561+ assertEquals (
1562+ isIntersectionOf ( preds ) ( { b : "a" } ) ,
1563+ false ,
1564+ "Not a function object" ,
1565+ ) ;
1566+ assertEquals (
1567+ isIntersectionOf ( preds ) ( ( ) => void 0 ) ,
1568+ false ,
1569+ "Some properties does not exists in Function object" ,
1570+ ) ;
1571+ await testWithExamples ( t , isIntersectionOf ( preds ) , {
1572+ excludeExamples : [ "record" ] ,
1573+ } ) ;
1574+ } ) ;
15181575} ) ;
15191576
15201577Deno . test ( "isRequiredOf<T>" , async ( t ) => {
0 commit comments