1- export class Arg {
1+ class Arg {
22 private constructor (
33 private description : string ,
44 private matchingFunction : ( arg : any ) => boolean
55 ) {
6-
76 }
87
98 matches ( arg : any ) {
@@ -20,10 +19,13 @@ export class Arg {
2019
2120 static any ( )
2221 static any < T extends 'string' | 'number' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'array' > ( type : T )
23- static any ( type ?: string ) {
22+ static any ( type ?: string ) : any {
2423 const description = ! type ? '{any arg}' : '{arg matching ' + type + '}' ;
2524 return new Arg ( description , x => {
26- if ( typeof type !== 'string' )
25+ if ( typeof type === 'string' )
26+ return true ;
27+
28+ if ( typeof type === 'undefined' )
2729 return true ;
2830
2931 if ( type === 'array' )
@@ -33,13 +35,13 @@ export class Arg {
3335 } ) ;
3436 }
3537
36- static is < T > ( value : T )
37- static is < T > ( predicate : ( input : T ) => boolean )
38- static is < T > ( predicateOrValue : ( ( input : T ) => boolean ) | T ) {
38+ static is < T > ( value : T ) : Arg & T
39+ static is < T > ( predicate : ( input : T ) => boolean ) : Arg & T
40+ static is < T > ( predicateOrValue : ( ( input : T ) => boolean ) | T ) : Arg & T {
3941 if ( typeof predicateOrValue === 'function' )
40- return new Arg ( '{arg matching predicate ' + this . toStringify ( predicateOrValue ) + '}' , predicateOrValue ) ;
42+ return new Arg ( '{arg matching predicate ' + this . toStringify ( predicateOrValue ) + '}' , predicateOrValue ) as any ;
4143
42- return new Arg ( '{arg matching ' + this . toStringify ( predicateOrValue ) + '}' , x => x === predicateOrValue ) ;
44+ return new Arg ( '{arg matching ' + this . toStringify ( predicateOrValue ) + '}' , x => x === predicateOrValue ) as any ;
4345 }
4446
4547 private static toStringify ( obj : any ) {
0 commit comments