Skip to content

Commit 5f92c85

Browse files
authored
Merge pull request #62 from lambdalisue/fix-isrecord
👍 Add `isRecordLike` and `isRecordLikeOf`, fix `isObjectOf` that should not allow `Array`
2 parents ee90c24 + a5a1584 commit 5f92c85

File tree

9 files changed

+295
-119
lines changed

9 files changed

+295
-119
lines changed

deno.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
},
66
"tasks": {
77
"build-npm": "deno run -A scripts/build_npm.ts $(git describe --tags --always --dirty)",
8-
"test": "deno test -A --parallel --shuffle --doc",
8+
"test": "deno test -A --parallel --doc",
99
"test:coverage": "deno task test --coverage=.coverage",
1010
"check": "deno check ./**/*.ts",
1111
"coverage": "deno coverage .coverage --exclude=is_bench.ts",
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
export const snapshot = {};
22

3-
snapshot[`isAllOf<T> > returns properly named function 1`] = `
4-
"isObjectOf({
5-
a: isNumber,
6-
b: isString
7-
})"
8-
`;
9-
103
snapshot[`isOneOf<T> > returns properly named function 1`] = `
114
"isUnionOf([
125
isNumber,
136
isString,
147
isBoolean
158
])"
169
`;
10+
11+
snapshot[`isAllOf<T> > returns properly named function 1`] = `
12+
"isObjectOf({
13+
a: isNumber,
14+
b: isString
15+
})"
16+
`;

is/__snapshots__/annotation_test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ snapshot[`isUnwrapOptionalOf<T> > returns properly named function 2`] = `"isNumb
1010
1111
snapshot[`isUnwrapOptionalOf<T> > returns properly named function 3`] = `"isNumber"`;
1212
13-
snapshot[`isUnwrapReadonlyOf<T> > returns properly named function 1`] = `"isNumber"`;
14-
15-
snapshot[`isUnwrapReadonlyOf<T> > returns properly named function 2`] = `"isReadonlyOf(isNumber)"`;
16-
1713
snapshot[`isReadonlyOf<T> > returns properly named function 1`] = `"isReadonlyOf(isNumber)"`;
1814
1915
snapshot[`isReadonlyOf<T> > returns properly named function 2`] = `"isReadonlyOf(isReadonlyOf(isNumber))"`;
16+
17+
snapshot[`isUnwrapReadonlyOf<T> > returns properly named function 1`] = `"isNumber"`;
18+
19+
snapshot[`isUnwrapReadonlyOf<T> > returns properly named function 2`] = `"isReadonlyOf(isNumber)"`;
Lines changed: 88 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,9 @@
11
export const snapshot = {};
22

3-
snapshot[`isObjectOf<T> > returns properly named function 1`] = `
4-
"isObjectOf({
5-
a: isNumber,
6-
b: isString,
7-
c: isBoolean
8-
})"
9-
`;
10-
11-
snapshot[`isObjectOf<T> > returns properly named function 2`] = `"isObjectOf({a: a})"`;
12-
13-
snapshot[`isObjectOf<T> > returns properly named function 3`] = `
14-
"isObjectOf({
15-
a: isObjectOf({
16-
b: isObjectOf({c: isBoolean})
17-
})
18-
})"
19-
`;
20-
213
snapshot[`isArrayOf<T> > returns properly named function 1`] = `"isArrayOf(isNumber)"`;
224
235
snapshot[`isArrayOf<T> > returns properly named function 2`] = `"isArrayOf((anonymous))"`;
246
25-
snapshot[`isReadonlyTupleOf<T> > returns properly named function 1`] = `
26-
"isReadonlyOf(isTupleOf([
27-
isNumber,
28-
isString,
29-
isBoolean
30-
]))"
31-
`;
32-
33-
snapshot[`isReadonlyTupleOf<T> > returns properly named function 2`] = `"isReadonlyOf(isTupleOf([(anonymous)]))"`;
34-
35-
snapshot[`isReadonlyTupleOf<T> > returns properly named function 3`] = `
36-
"isReadonlyOf(isTupleOf([
37-
isReadonlyOf(isTupleOf([
38-
isReadonlyOf(isTupleOf([
39-
isNumber,
40-
isString,
41-
isBoolean
42-
]))
43-
]))
44-
]))"
45-
`;
46-
477
snapshot[`isSetOf<T> > returns properly named function 1`] = `"isSetOf(isNumber)"`;
488
499
snapshot[`isSetOf<T> > returns properly named function 2`] = `"isSetOf((anonymous))"`;
@@ -70,64 +30,126 @@ snapshot[`isTupleOf<T> > returns properly named function 3`] = `
7030
])"
7131
`;
7232
73-
snapshot[`isRecordOf<T> > returns properly named function 1`] = `"isRecordOf(isNumber, undefined)"`;
33+
snapshot[`isTupleOf<T, E> > returns properly named function 1`] = `
34+
"isTupleOf([
35+
isNumber,
36+
isString,
37+
isBoolean
38+
], isArray)"
39+
`;
7440
75-
snapshot[`isRecordOf<T> > returns properly named function 2`] = `"isRecordOf((anonymous), undefined)"`;
41+
snapshot[`isTupleOf<T, E> > returns properly named function 2`] = `"isTupleOf([(anonymous)], isArrayOf(isString))"`;
7642
77-
snapshot[`isReadonlyTupleOf<T, E> > returns properly named function 1`] = `
43+
snapshot[`isTupleOf<T, E> > returns properly named function 3`] = `
44+
"isTupleOf([
45+
isTupleOf([
46+
isTupleOf([
47+
isNumber,
48+
isString,
49+
isBoolean
50+
], isArray)
51+
], isArray)
52+
])"
53+
`;
54+
55+
snapshot[`isReadonlyTupleOf<T> > returns properly named function 1`] = `
7856
"isReadonlyOf(isTupleOf([
7957
isNumber,
8058
isString,
8159
isBoolean
82-
], isArray))"
60+
]))"
8361
`;
8462
85-
snapshot[`isReadonlyTupleOf<T, E> > returns properly named function 2`] = `"isReadonlyOf(isTupleOf([(anonymous)], isArrayOf(isString)))"`;
63+
snapshot[`isReadonlyTupleOf<T> > returns properly named function 2`] = `"isReadonlyOf(isTupleOf([(anonymous)]))"`;
8664
87-
snapshot[`isReadonlyTupleOf<T, E> > returns properly named function 3`] = `
65+
snapshot[`isReadonlyTupleOf<T> > returns properly named function 3`] = `
8866
"isReadonlyOf(isTupleOf([
8967
isReadonlyOf(isTupleOf([
9068
isReadonlyOf(isTupleOf([
9169
isNumber,
9270
isString,
9371
isBoolean
94-
], isArray))
95-
], isArray))
96-
], isArray))"
72+
]))
73+
]))
74+
]))"
9775
`;
9876
99-
snapshot[`isTupleOf<T, E> > returns properly named function 1`] = `
100-
"isTupleOf([
77+
snapshot[`isReadonlyTupleOf<T, E> > returns properly named function 1`] = `
78+
"isReadonlyOf(isTupleOf([
10179
isNumber,
10280
isString,
10381
isBoolean
104-
], isArray)"
82+
], isArray))"
10583
`;
10684
107-
snapshot[`isTupleOf<T, E> > returns properly named function 2`] = `"isTupleOf([(anonymous)], isArrayOf(isString))"`;
85+
snapshot[`isReadonlyTupleOf<T, E> > returns properly named function 2`] = `"isReadonlyOf(isTupleOf([(anonymous)], isArrayOf(isString)))"`;
10886
109-
snapshot[`isTupleOf<T, E> > returns properly named function 3`] = `
110-
"isTupleOf([
111-
isTupleOf([
112-
isTupleOf([
87+
snapshot[`isReadonlyTupleOf<T, E> > returns properly named function 3`] = `
88+
"isReadonlyOf(isTupleOf([
89+
isReadonlyOf(isTupleOf([
90+
isReadonlyOf(isTupleOf([
11391
isNumber,
11492
isString,
11593
isBoolean
116-
], isArray)
117-
], isArray)
118-
])"
94+
], isArray))
95+
], isArray))
96+
], isArray))"
11997
`;
12098
121-
snapshot[`isInstanceOf<T> > returns properly named function 1`] = `"isInstanceOf(Date)"`;
99+
snapshot[`isUniformTupleOf<T> > returns properly named function 1`] = `"isUniformTupleOf(3, isAny)"`;
122100
123-
snapshot[`isInstanceOf<T> > returns properly named function 2`] = `"isInstanceOf((anonymous))"`;
101+
snapshot[`isUniformTupleOf<T> > returns properly named function 2`] = `"isUniformTupleOf(3, isNumber)"`;
124102
125-
snapshot[`isLiteralOneOf<T> > returns properly named function 1`] = `'isLiteralOneOf(["hello", "world"])'`;
103+
snapshot[`isUniformTupleOf<T> > returns properly named function 3`] = `"isUniformTupleOf(3, (anonymous))"`;
104+
105+
snapshot[`isReadonlyUniformTupleOf<T> > returns properly named function 1`] = `"isReadonlyOf(isUniformTupleOf(3, isAny))"`;
106+
107+
snapshot[`isReadonlyUniformTupleOf<T> > returns properly named function 2`] = `"isReadonlyOf(isUniformTupleOf(3, isNumber))"`;
108+
109+
snapshot[`isReadonlyUniformTupleOf<T> > returns properly named function 3`] = `"isReadonlyOf(isUniformTupleOf(3, (anonymous)))"`;
110+
111+
snapshot[`isRecordOf<T> > returns properly named function 1`] = `"isRecordOf(isNumber, undefined)"`;
112+
113+
snapshot[`isRecordOf<T> > returns properly named function 2`] = `"isRecordOf((anonymous), undefined)"`;
114+
115+
snapshot[`isRecordOf<T, K> > returns properly named function 1`] = `"isRecordOf(isNumber, isString)"`;
116+
117+
snapshot[`isRecordOf<T, K> > returns properly named function 2`] = `"isRecordOf((anonymous), isString)"`;
118+
119+
snapshot[`isRecordLikeOf<T> > returns properly named function 1`] = `"isRecordLikeOf(isNumber, undefined)"`;
120+
121+
snapshot[`isRecordLikeOf<T> > returns properly named function 2`] = `"isRecordLikeOf((anonymous), undefined)"`;
122+
123+
snapshot[`isRecordLikeOf<T, K> > returns properly named function 1`] = `"isRecordLikeOf(isNumber, isString)"`;
124+
125+
snapshot[`isRecordLikeOf<T, K> > returns properly named function 2`] = `"isRecordLikeOf((anonymous), isString)"`;
126126
127127
snapshot[`isMapOf<T> > returns properly named function 1`] = `"isMapOf(isNumber, undefined)"`;
128128
129129
snapshot[`isMapOf<T> > returns properly named function 2`] = `"isMapOf((anonymous), undefined)"`;
130130
131+
snapshot[`isMapOf<T, K> > returns properly named function 1`] = `"isMapOf(isNumber, isString)"`;
132+
133+
snapshot[`isMapOf<T, K> > returns properly named function 2`] = `"isMapOf((anonymous), isString)"`;
134+
135+
snapshot[`isObjectOf<T> > returns properly named function 1`] = `
136+
"isObjectOf({
137+
a: isNumber,
138+
b: isString,
139+
c: isBoolean
140+
})"
141+
`;
142+
143+
snapshot[`isObjectOf<T> > returns properly named function 2`] = `"isObjectOf({a: a})"`;
144+
145+
snapshot[`isObjectOf<T> > returns properly named function 3`] = `
146+
"isObjectOf({
147+
a: isObjectOf({
148+
b: isObjectOf({c: isBoolean})
149+
})
150+
})"
151+
`;
152+
131153
snapshot[`isStrictOf<T> > returns properly named function 1`] = `
132154
"isStrictOf(isObjectOf({
133155
a: isNumber,
@@ -146,9 +168,9 @@ snapshot[`isStrictOf<T> > returns properly named function 3`] = `
146168
}))"
147169
`;
148170
149-
snapshot[`isRecordOf<T, K> > returns properly named function 1`] = `"isRecordOf(isNumber, isString)"`;
171+
snapshot[`isInstanceOf<T> > returns properly named function 1`] = `"isInstanceOf(Date)"`;
150172
151-
snapshot[`isRecordOf<T, K> > returns properly named function 2`] = `"isRecordOf((anonymous), isString)"`;
173+
snapshot[`isInstanceOf<T> > returns properly named function 2`] = `"isInstanceOf((anonymous))"`;
152174
153175
snapshot[`isLiteralOf<T> > returns properly named function 1`] = `'isLiteralOf("hello")'`;
154176
@@ -164,18 +186,4 @@ snapshot[`isLiteralOf<T> > returns properly named function 6`] = `"isLiteralOf(u
164186
165187
snapshot[`isLiteralOf<T> > returns properly named function 7`] = `"isLiteralOf(Symbol(asdf))"`;
166188
167-
snapshot[`isMapOf<T, K> > returns properly named function 1`] = `"isMapOf(isNumber, isString)"`;
168-
169-
snapshot[`isMapOf<T, K> > returns properly named function 2`] = `"isMapOf((anonymous), isString)"`;
170-
171-
snapshot[`isUniformTupleOf<T> > returns properly named function 1`] = `"isUniformTupleOf(3, isAny)"`;
172-
173-
snapshot[`isUniformTupleOf<T> > returns properly named function 2`] = `"isUniformTupleOf(3, isNumber)"`;
174-
175-
snapshot[`isUniformTupleOf<T> > returns properly named function 3`] = `"isUniformTupleOf(3, (anonymous))"`;
176-
177-
snapshot[`isReadonlyUniformTupleOf<T> > returns properly named function 1`] = `"isReadonlyOf(isUniformTupleOf(3, isAny))"`;
178-
179-
snapshot[`isReadonlyUniformTupleOf<T> > returns properly named function 2`] = `"isReadonlyOf(isUniformTupleOf(3, isNumber))"`;
180-
181-
snapshot[`isReadonlyUniformTupleOf<T> > returns properly named function 3`] = `"isReadonlyOf(isUniformTupleOf(3, (anonymous)))"`;
189+
snapshot[`isLiteralOneOf<T> > returns properly named function 1`] = `'isLiteralOneOf(["hello", "world"])'`;

is/__snapshots__/utility_test.ts.snap

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,34 @@ snapshot[`isUnionOf<T> > returns properly named function 1`] = `
88
])"
99
`;
1010
11-
snapshot[`isOmitOf<T, K> > returns properly named function 1`] = `
11+
snapshot[`isIntersectionOf<T> > returns properly named function 1`] = `
12+
"isObjectOf({
13+
a: isNumber,
14+
b: isString
15+
})"
16+
`;
17+
18+
snapshot[`isRequiredOf<T> > returns properly named function 1`] = `
1219
"isObjectOf({
1320
a: isNumber,
21+
b: isUnionOf([
22+
isString,
23+
isUndefined
24+
]),
1425
c: isBoolean
1526
})"
1627
`;
1728
18-
snapshot[`isOmitOf<T, K> > returns properly named function 2`] = `"isObjectOf({a: isNumber})"`;
29+
snapshot[`isRequiredOf<T> > returns properly named function 2`] = `
30+
"isObjectOf({
31+
a: isNumber,
32+
b: isUnionOf([
33+
isString,
34+
isUndefined
35+
]),
36+
c: isBoolean
37+
})"
38+
`;
1939
2040
snapshot[`isPartialOf<T> > returns properly named function 1`] = `
2141
"isObjectOf({
@@ -48,31 +68,11 @@ snapshot[`isPickOf<T, K> > returns properly named function 1`] = `
4868
4969
snapshot[`isPickOf<T, K> > returns properly named function 2`] = `"isObjectOf({a: isNumber})"`;
5070
51-
snapshot[`isRequiredOf<T> > returns properly named function 1`] = `
52-
"isObjectOf({
53-
a: isNumber,
54-
b: isUnionOf([
55-
isString,
56-
isUndefined
57-
]),
58-
c: isBoolean
59-
})"
60-
`;
61-
62-
snapshot[`isRequiredOf<T> > returns properly named function 2`] = `
71+
snapshot[`isOmitOf<T, K> > returns properly named function 1`] = `
6372
"isObjectOf({
6473
a: isNumber,
65-
b: isUnionOf([
66-
isString,
67-
isUndefined
68-
]),
6974
c: isBoolean
7075
})"
7176
`;
7277
73-
snapshot[`isIntersectionOf<T> > returns properly named function 1`] = `
74-
"isObjectOf({
75-
a: isNumber,
76-
b: isString
77-
})"
78-
`;
78+
snapshot[`isOmitOf<T, K> > returns properly named function 2`] = `"isObjectOf({a: isNumber})"`;

0 commit comments

Comments
 (0)