@@ -18,6 +18,7 @@ import is, {
1818 isNumber ,
1919 isObjectOf ,
2020 isOneOf ,
21+ isOptionalOf ,
2122 isRecord ,
2223 isRecordOf ,
2324 isString ,
@@ -346,6 +347,65 @@ Deno.test("isOneOf<T>", async (t) => {
346347 } ) ;
347348} ) ;
348349
350+ Deno . test ( "isOptionalOf<T>" , async ( t ) => {
351+ await t . step ( "returns proper type predicate" , ( ) => {
352+ const a : unknown = undefined ;
353+ if ( isOptionalOf ( isNumber ) ( a ) ) {
354+ type _ = AssertTrue < IsExact < typeof a , number | undefined > > ;
355+ }
356+ } ) ;
357+ await t . step ( "with isString" , async ( t ) => {
358+ await testWithExamples ( t , isOptionalOf ( isString ) , {
359+ validExamples : [ "string" , "undefined" ] ,
360+ } ) ;
361+ } ) ;
362+ await t . step ( "with isNumber" , async ( t ) => {
363+ await testWithExamples ( t , isOptionalOf ( isNumber ) , {
364+ validExamples : [ "number" , "undefined" ] ,
365+ } ) ;
366+ } ) ;
367+ await t . step ( "with isBigInt" , async ( t ) => {
368+ await testWithExamples ( t , isOptionalOf ( isBigInt ) , {
369+ validExamples : [ "bigint" , "undefined" ] ,
370+ } ) ;
371+ } ) ;
372+ await t . step ( "with isBoolean" , async ( t ) => {
373+ await testWithExamples ( t , isOptionalOf ( isBoolean ) , {
374+ validExamples : [ "boolean" , "undefined" ] ,
375+ } ) ;
376+ } ) ;
377+ await t . step ( "with isArray" , async ( t ) => {
378+ await testWithExamples ( t , isOptionalOf ( isArray ) , {
379+ validExamples : [ "array" , "undefined" ] ,
380+ } ) ;
381+ } ) ;
382+ await t . step ( "with isRecord" , async ( t ) => {
383+ await testWithExamples ( t , isOptionalOf ( isRecord ) , {
384+ validExamples : [ "record" , "date" , "promise" , "undefined" ] ,
385+ } ) ;
386+ } ) ;
387+ await t . step ( "with isFunction" , async ( t ) => {
388+ await testWithExamples ( t , isOptionalOf ( isFunction ) , {
389+ validExamples : [ "function" , "undefined" ] ,
390+ } ) ;
391+ } ) ;
392+ await t . step ( "with isNull" , async ( t ) => {
393+ await testWithExamples ( t , isOptionalOf ( isNull ) , {
394+ validExamples : [ "null" , "undefined" ] ,
395+ } ) ;
396+ } ) ;
397+ await t . step ( "with isUndefined" , async ( t ) => {
398+ await testWithExamples ( t , isOptionalOf ( isUndefined ) , {
399+ validExamples : [ "undefined" ] ,
400+ } ) ;
401+ } ) ;
402+ await t . step ( "with isSymbol" , async ( t ) => {
403+ await testWithExamples ( t , isOptionalOf ( isSymbol ) , {
404+ validExamples : [ "symbol" , "undefined" ] ,
405+ } ) ;
406+ } ) ;
407+ } ) ;
408+
349409Deno . test ( "is" , async ( t ) => {
350410 const mod = await import ( "./is.ts" ) ;
351411 const casesOfAliasAndIsFunction = Object . entries ( mod )
0 commit comments