@@ -5,10 +5,7 @@ import {
55import {
66 assertSnapshot ,
77} from "https://deno.land/[email protected] /testing/snapshot.ts" ; 8- import {
9- assertType ,
10- type IsExact ,
11- } from "https://deno.land/[email protected] /testing/types.ts" ; 8+ import { assertType } from "https://deno.land/[email protected] /testing/types.ts" ; 129import is , {
1310 isAllOf ,
1411 isAny ,
@@ -48,6 +45,11 @@ import is, {
4845 UniformTupleOf ,
4946} from "./is.ts" ;
5047
48+ // It seems 'IsExact' in deno_std is false positive so use `Equal` in type-challenges
49+ // https://github.com/type-challenges/type-challenges/blob/e77262dba62e9254451f661cb4fe5517ffd1d933/utils/index.d.ts#L7-L9
50+ type Equal < X , Y > = ( < T > ( ) => T extends X ? 1 : 2 ) extends
51+ ( < T > ( ) => T extends Y ? 1 : 2 ) ? true : false ;
52+
5153const examples = {
5254 string : [ "" , "Hello world" ] ,
5355 number : [ 0 , 1234567890 ] ,
@@ -112,7 +114,7 @@ Deno.test("PredicateType", () => {
112114 ] ) ) ,
113115 } ) ;
114116 assertType <
115- IsExact < PredicateType < typeof isArticle > , {
117+ Equal < PredicateType < typeof isArticle > , {
116118 title : string ;
117119 body : string ;
118120 refs : ( string | { name : string ; url : string } ) [ ] ;
@@ -188,7 +190,7 @@ Deno.test("isArrayOf<T>", async (t) => {
188190 await t . step ( "returns proper type predicate" , ( ) => {
189191 const a : unknown = [ 0 , 1 , 2 ] ;
190192 if ( isArrayOf ( isNumber ) ( a ) ) {
191- assertType < IsExact < typeof a , number [ ] > > ( true ) ;
193+ assertType < Equal < typeof a , number [ ] > > ( true ) ;
192194 }
193195 } ) ;
194196 await t . step ( "returns true on T array" , ( ) => {
@@ -208,7 +210,7 @@ Deno.test("isArrayOf<T>", async (t) => {
208210
209211Deno . test ( "TupleOf<T>" , ( ) => {
210212 assertType <
211- IsExact <
213+ Equal <
212214 TupleOf < readonly [ typeof is . String , typeof is . Number ] > ,
213215 [ string , number ]
214216 >
@@ -217,7 +219,7 @@ Deno.test("TupleOf<T>", () => {
217219
218220Deno . test ( "ReadonlyTupleOf<T>" , ( ) => {
219221 assertType <
220- IsExact <
222+ Equal <
221223 ReadonlyTupleOf < readonly [ typeof is . String , typeof is . Number ] > ,
222224 readonly [ string , number ]
223225 >
@@ -248,7 +250,7 @@ Deno.test("isTupleOf<T>", async (t) => {
248250 const predTup = [ isNumber , isString , isBoolean ] as const ;
249251 const a : unknown = [ 0 , "a" , true ] ;
250252 if ( isTupleOf ( predTup ) ( a ) ) {
251- assertType < IsExact < typeof a , [ number , string , boolean ] > > ( true ) ;
253+ assertType < Equal < typeof a , [ number , string , boolean ] > > ( true ) ;
252254 }
253255 } ) ;
254256 await t . step ( "returns true on T tuple" , ( ) => {
@@ -304,7 +306,7 @@ Deno.test("isTupleOf<T, E>", async (t) => {
304306 const predElse = is . ArrayOf ( is . Number ) ;
305307 const a : unknown = [ 0 , "a" , true , 0 , 1 , 2 ] ;
306308 if ( isTupleOf ( predTup , predElse ) ( a ) ) {
307- assertType < IsExact < typeof a , [ number , string , boolean , ...number [ ] ] > > (
309+ assertType < Equal < typeof a , [ number , string , boolean , ...number [ ] ] > > (
308310 true ,
309311 ) ;
310312 }
@@ -374,7 +376,7 @@ Deno.test("isReadonlyTupleOf<T>", async (t) => {
374376 const predTup = [ isNumber , isString , isBoolean ] as const ;
375377 const a : unknown = [ 0 , "a" , true ] ;
376378 if ( isReadonlyTupleOf ( predTup ) ( a ) ) {
377- assertType < IsExact < typeof a , readonly [ number , string , boolean ] > > ( true ) ;
379+ assertType < Equal < typeof a , readonly [ number , string , boolean ] > > ( true ) ;
378380 }
379381 } ) ;
380382 await t . step ( "returns true on T tuple" , ( ) => {
@@ -441,7 +443,7 @@ Deno.test("isReadonlyTupleOf<T, E>", async (t) => {
441443 const a : unknown = [ 0 , "a" , true , 0 , 1 , 2 ] ;
442444 if ( isReadonlyTupleOf ( predTup , predElse ) ( a ) ) {
443445 assertType <
444- IsExact < typeof a , readonly [ number , string , boolean , ...number [ ] ] >
446+ Equal < typeof a , readonly [ number , string , boolean , ...number [ ] ] >
445447 > ( true ) ;
446448 }
447449 } ) ;
@@ -495,13 +497,13 @@ Deno.test("isReadonlyTupleOf<T, E>", async (t) => {
495497
496498Deno . test ( "UniformTupleOf<N, T>" , ( ) => {
497499 assertType <
498- IsExact < UniformTupleOf < number , 5 > , [ number , number , number , number , number ] >
500+ Equal < UniformTupleOf < number , 5 > , [ number , number , number , number , number ] >
499501 > ( true ) ;
500502} ) ;
501503
502504Deno . test ( "ReadonlyUniformTupleOf<N, T>" , ( ) => {
503505 assertType <
504- IsExact <
506+ Equal <
505507 ReadonlyUniformTupleOf < number , 5 > ,
506508 readonly [
507509 number ,
@@ -527,12 +529,12 @@ Deno.test("isUniformTupleOf<T>", async (t) => {
527529 const a : unknown = [ 0 , 1 , 2 , 3 , 4 ] ;
528530 if ( isUniformTupleOf ( 5 ) ( a ) ) {
529531 assertType <
530- IsExact < typeof a , [ unknown , unknown , unknown , unknown , unknown ] >
532+ Equal < typeof a , [ unknown , unknown , unknown , unknown , unknown ] >
531533 > ( true ) ;
532534 }
533535
534536 if ( isUniformTupleOf ( 5 , isNumber ) ( a ) ) {
535- assertType < IsExact < typeof a , [ number , number , number , number , number ] > > (
537+ assertType < Equal < typeof a , [ number , number , number , number , number ] > > (
536538 true ,
537539 ) ;
538540 }
@@ -564,7 +566,7 @@ Deno.test("isReadonlyUniformTupleOf<T>", async (t) => {
564566 const a : unknown = [ 0 , 1 , 2 , 3 , 4 ] ;
565567 if ( isReadonlyUniformTupleOf ( 5 ) ( a ) ) {
566568 assertType <
567- IsExact <
569+ Equal <
568570 typeof a ,
569571 readonly [ unknown , unknown , unknown , unknown , unknown ]
570572 >
@@ -573,7 +575,7 @@ Deno.test("isReadonlyUniformTupleOf<T>", async (t) => {
573575
574576 if ( isReadonlyUniformTupleOf ( 5 , isNumber ) ( a ) ) {
575577 assertType <
576- IsExact < typeof a , readonly [ number , number , number , number , number ] >
578+ Equal < typeof a , readonly [ number , number , number , number , number ] >
577579 > ( true ) ;
578580 }
579581 } ) ;
@@ -608,7 +610,7 @@ Deno.test("isRecordOf<T>", async (t) => {
608610 await t . step ( "returns proper type predicate" , ( ) => {
609611 const a : unknown = { a : 0 } ;
610612 if ( isRecordOf ( isNumber ) ( a ) ) {
611- assertType < IsExact < typeof a , Record < PropertyKey , number > > > ( true ) ;
613+ assertType < Equal < typeof a , Record < PropertyKey , number > > > ( true ) ;
612614 }
613615 } ) ;
614616 await t . step ( "returns true on T record" , ( ) => {
@@ -637,7 +639,7 @@ Deno.test("isRecordOf<T, K>", async (t) => {
637639 await t . step ( "returns proper type predicate" , ( ) => {
638640 const a : unknown = { a : 0 } ;
639641 if ( isRecordOf ( isNumber , isString ) ( a ) ) {
640- assertType < IsExact < typeof a , Record < string , number > > > ( true ) ;
642+ assertType < Equal < typeof a , Record < string , number > > > ( true ) ;
641643 }
642644 } ) ;
643645 await t . step ( "returns true on T record" , ( ) => {
@@ -662,7 +664,7 @@ Deno.test("isRecordOf<T, K>", async (t) => {
662664
663665Deno . test ( "ObjectOf<T>" , ( ) => {
664666 assertType <
665- IsExact <
667+ Equal <
666668 ObjectOf < { a : typeof is . Number ; b : typeof is . String } > ,
667669 { a : number ; b : string }
668670 >
@@ -693,7 +695,7 @@ Deno.test("isObjectOf<T>", async (t) => {
693695 } ;
694696 const a : unknown = { a : 0 , b : "a" , c : true } ;
695697 if ( isObjectOf ( predObj ) ( a ) ) {
696- assertType < IsExact < typeof a , { a : number ; b : string ; c : boolean } > > ( true ) ;
698+ assertType < Equal < typeof a , { a : number ; b : string ; c : boolean } > > ( true ) ;
697699 }
698700 } ) ;
699701 await t . step ( "returns true on T object" , ( ) => {
@@ -757,7 +759,7 @@ Deno.test("isObjectOf<T>", async (t) => {
757759 const a : unknown = { a : 0 , b : "a" } ;
758760 if ( isObjectOf ( predObj ) ( a ) ) {
759761 assertType <
760- IsExact < typeof a , { a : number ; b : string | undefined ; c ?: boolean } >
762+ Equal < typeof a , { a : number ; b : string | undefined ; c ?: boolean } >
761763 > ( true ) ;
762764 }
763765 } ) ;
@@ -833,7 +835,7 @@ Deno.test("isFunction", async (t) => {
833835 validExamples : [ "syncFunction" , "asyncFunction" ] ,
834836 } ) ;
835837 assertType <
836- IsExact < PredicateType < typeof isFunction > , ( ...args : unknown [ ] ) => unknown >
838+ Equal < PredicateType < typeof isFunction > , ( ...args : unknown [ ] ) => unknown >
837839 > ( true ) ;
838840} ) ;
839841
@@ -842,7 +844,7 @@ Deno.test("isSyncFunction", async (t) => {
842844 validExamples : [ "syncFunction" ] ,
843845 } ) ;
844846 assertType <
845- IsExact <
847+ Equal <
846848 PredicateType < typeof isSyncFunction > ,
847849 ( ...args : unknown [ ] ) => unknown
848850 >
@@ -854,7 +856,7 @@ Deno.test("isAsyncFunction", async (t) => {
854856 validExamples : [ "asyncFunction" ] ,
855857 } ) ;
856858 assertType <
857- IsExact <
859+ Equal <
858860 PredicateType < typeof isAsyncFunction > ,
859861 ( ...args : unknown [ ] ) => Promise < unknown >
860862 >
@@ -888,17 +890,17 @@ Deno.test("isInstanceOf<T>", async (t) => {
888890 class Cls { }
889891 const a : unknown = new Cls ( ) ;
890892 if ( isInstanceOf ( Cls ) ( a ) ) {
891- assertType < IsExact < typeof a , Cls > > ( true ) ;
893+ assertType < Equal < typeof a , Cls > > ( true ) ;
892894 }
893895
894896 const b : unknown = new Date ( ) ;
895897 if ( isInstanceOf ( Date ) ( b ) ) {
896- assertType < IsExact < typeof b , Date > > ( true ) ;
898+ assertType < Equal < typeof b , Date > > ( true ) ;
897899 }
898900
899901 const c : unknown = new Promise ( ( ) => { } ) ;
900902 if ( isInstanceOf ( Promise ) ( c ) ) {
901- assertType < IsExact < typeof c , Promise < unknown > > > ( true ) ;
903+ assertType < Equal < typeof c , Promise < unknown > > > ( true ) ;
902904 }
903905 } ) ;
904906} ) ;
@@ -949,7 +951,7 @@ Deno.test("isLiteralOf<T>", async (t) => {
949951 const pred = "hello" ;
950952 const a : unknown = "hello" ;
951953 if ( isLiteralOf ( pred ) ( a ) ) {
952- assertType < IsExact < typeof a , "hello" > > ( true ) ;
954+ assertType < Equal < typeof a , "hello" > > ( true ) ;
953955 }
954956 } ) ;
955957 await t . step ( "returns true on literal T" , ( ) => {
@@ -970,7 +972,7 @@ Deno.test("isLiteralOneOf<T>", async (t) => {
970972 const preds = [ "hello" , "world" ] as const ;
971973 const a : unknown = "hello" ;
972974 if ( isLiteralOneOf ( preds ) ( a ) ) {
973- assertType < IsExact < typeof a , "hello" | "world" > > ( true ) ;
975+ assertType < Equal < typeof a , "hello" | "world" > > ( true ) ;
974976 }
975977 } ) ;
976978 await t . step ( "returns true on literal T" , ( ) => {
@@ -992,7 +994,7 @@ Deno.test("isOneOf<T>", async (t) => {
992994 const preds = [ isNumber , isString , isBoolean ] ;
993995 const a : unknown = [ 0 , "a" , true ] ;
994996 if ( isOneOf ( preds ) ( a ) ) {
995- assertType < IsExact < typeof a , number | string | boolean > > ( true ) ;
997+ assertType < Equal < typeof a , number | string | boolean > > ( true ) ;
996998 }
997999 } ) ;
9981000 await t . step ( "returns true on one of T" , ( ) => {
@@ -1026,7 +1028,7 @@ Deno.test("isAllOf<T>", async (t) => {
10261028 ] ;
10271029 const a : unknown = { a : 0 , b : "a" } ;
10281030 if ( isAllOf ( preds ) ( a ) ) {
1029- assertType < IsExact < typeof a , { a : number ; b : string } > > ( true ) ;
1031+ assertType < Equal < typeof a , { a : number } & { b : string } > > ( true ) ;
10301032 }
10311033 } ) ;
10321034 await t . step ( "returns true on all of T" , ( ) => {
@@ -1064,7 +1066,7 @@ Deno.test("isOptionalOf<T>", async (t) => {
10641066 await t . step ( "returns proper type predicate" , ( ) => {
10651067 const a : unknown = undefined ;
10661068 if ( isOptionalOf ( isNumber ) ( a ) ) {
1067- assertType < IsExact < typeof a , number | undefined > > ( true ) ;
1069+ assertType < Equal < typeof a , number | undefined > > ( true ) ;
10681070 }
10691071 } ) ;
10701072 await t . step ( "with isString" , async ( t ) => {
0 commit comments