Skip to content

Commit 3db9dcd

Browse files
committed
Improve type checking of propType validators
1 parent 2f7fc87 commit 3db9dcd

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/shared/propTypes.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import PropTypes from 'prop-types';
22

3+
import type { Validator } from 'prop-types';
4+
35
const allViews = ['century', 'decade', 'year', 'month'];
46
const allValueTypes = [...allViews.slice(1), 'day'];
57

68
export const isValueType = PropTypes.oneOf(allValueTypes);
79

8-
export function isMinDate(props: Record<string, unknown>, propName: string, componentName: string) {
10+
export const isMinDate: Validator<Date | null | undefined> = function isMinDate(
11+
props,
12+
propName,
13+
componentName,
14+
) {
915
const { [propName]: minDate } = props;
1016

1117
if (!minDate) {
@@ -27,9 +33,13 @@ export function isMinDate(props: Record<string, unknown>, propName: string, comp
2733
}
2834

2935
return null;
30-
}
36+
};
3137

32-
export function isMaxDate(props: Record<string, unknown>, propName: string, componentName: string) {
38+
export const isMaxDate: Validator<Date | null | undefined> = function isMaxDate(
39+
props,
40+
propName,
41+
componentName,
42+
) {
3343
const { [propName]: maxDate } = props;
3444

3545
if (!maxDate) {
@@ -51,7 +61,7 @@ export function isMaxDate(props: Record<string, unknown>, propName: string, comp
5161
}
5262

5363
return null;
54-
}
64+
};
5565

5666
export const isRef = PropTypes.oneOfType([
5767
PropTypes.func,

0 commit comments

Comments
 (0)