11export class Arg {
2- private constructor (
3- private description : string ,
4- private matchingFunction : ( arg : any ) => boolean
5- ) {
6- }
7-
8- matches ( arg : any ) {
9- return this . matchingFunction ( arg ) ;
10- }
11-
12- toString ( ) {
13- return this . description ;
14- }
15-
16- inspect ( ) {
17- return this . description ;
18- }
19-
202 static any ( )
213 static any < T extends 'string' | 'number' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'array' > ( type : T )
22- static any ( type ?: string ) : any {
4+ static any ( type ?: string ) : Argument < any > {
235 const description = ! type ? '{any arg}' : '{arg matching ' + type + '}' ;
24- return new Arg ( description , x => {
6+ return new Argument < any > ( description , x => {
257 if ( typeof type === 'string' )
268 return true ;
279
@@ -35,8 +17,8 @@ export class Arg {
3517 } ) ;
3618 }
3719
38- static is < T > ( predicate : ( input : T ) => boolean ) : Arg & T {
39- return new Arg ( '{arg matching predicate ' + this . toStringify ( predicate ) + '}' , predicate ) as any ;
20+ static is < T > ( predicate : ( input : T ) => boolean ) : Argument < T > {
21+ return new Argument < T > ( '{arg matching predicate ' + this . toStringify ( predicate ) + '}' , predicate ) as any ;
4022 }
4123
4224 private static toStringify ( obj : any ) {
@@ -48,4 +30,24 @@ export class Arg {
4830
4931 return obj ;
5032 }
33+ }
34+
35+ export class Argument < T > {
36+ constructor (
37+ private description : string ,
38+ private matchingFunction : ( arg : T ) => boolean
39+ ) {
40+ }
41+
42+ matches ( arg : T ) {
43+ return this . matchingFunction ( arg ) ;
44+ }
45+
46+ toString ( ) {
47+ return this . description ;
48+ }
49+
50+ inspect ( ) {
51+ return this . description ;
52+ }
5153}
0 commit comments