File tree Expand file tree Collapse file tree 4 files changed +19
-17
lines changed Expand file tree Collapse file tree 4 files changed +19
-17
lines changed Original file line number Diff line number Diff line change 1
1
import type { Predicate } from "./type.ts" ;
2
2
3
- export type Fn = ( ...args : unknown [ ] ) => unknown ;
3
+ // deno-lint-ignore no-explicit-any
4
+ export type Fn = ( ...args : any [ ] ) => unknown ;
4
5
5
6
export function annotate < F extends Fn , N extends string , V > (
6
7
fn : F ,
Original file line number Diff line number Diff line change @@ -3,7 +3,8 @@ import { inspect } from "./_inspect.ts";
3
3
/**
4
4
* Rewrite the function name.
5
5
*/
6
- export function rewriteName < F extends ( ...args : unknown [ ] ) => unknown > (
6
+ // deno-lint-ignore no-explicit-any
7
+ export function rewriteName < F extends ( ...args : any [ ] ) => unknown > (
7
8
fn : F ,
8
9
name : string ,
9
10
...args : unknown [ ]
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ export function isArrayOf<T>(
23
23
pred : Predicate < T > ,
24
24
) : Predicate < T [ ] > {
25
25
return rewriteName (
26
- ( x : unknown ) : x is T [ ] => isArray ( x ) && x . every ( pred ) ,
26
+ ( x : unknown ) : x is T [ ] => isArray ( x ) && x . every ( ( v ) => pred ( v ) ) ,
27
27
"isArrayOf" ,
28
28
pred ,
29
29
) ;
Original file line number Diff line number Diff line change @@ -43,22 +43,22 @@ export function isObjectOf<
43
43
...Object . keys ( predObj ) ,
44
44
...Object . getOwnPropertySymbols ( predObj ) ,
45
45
] . map ( ( k ) => [ k , predObj [ k ] ] ) ;
46
- return annotate (
47
- rewriteName (
48
- ( x : unknown ) : x is ObjectOf < T > => {
49
- if (
50
- x == null ||
51
- typeof x !== "object" && typeof x !== "function" ||
52
- Array . isArray ( x )
53
- ) return false ;
54
- return preds . every ( ( [ k , pred ] ) => pred ( ( x as T ) [ k ] ) ) ;
55
- } ,
56
- "isObjectOf" ,
57
- predObj ,
58
- ) ,
59
- "predObj" ,
46
+ const pred = rewriteName (
47
+ ( x ) : x is ObjectOf < T > => {
48
+ if ( ! isObject ( x ) ) return false ;
49
+ return preds . every ( ( [ k , pred ] ) => pred ( x [ k ] ) ) ;
50
+ } ,
51
+ "isObjectOf" ,
60
52
predObj ,
61
53
) ;
54
+ return annotate ( pred , "predObj" , predObj ) ;
55
+ }
56
+
57
+ function isObject ( x : unknown ) : x is Record < PropertyKey , unknown > {
58
+ if ( x == null ) return false ;
59
+ if ( typeof x !== "object" && typeof x !== "function" ) return false ;
60
+ if ( Array . isArray ( x ) ) return false ;
61
+ return true ;
62
62
}
63
63
64
64
type ObjectOf < T extends Record < PropertyKey , Predicate < unknown > > > = FlatType <
You can’t perform that action at this time.
0 commit comments