Skip to content

Commit

Permalink
Improve type checking of propType validators
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed May 28, 2023
1 parent 2f7fc87 commit 1fe8d94
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/shared/propTypes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import PropTypes from 'prop-types';

import type { Validator } from 'prop-types';

const allViews = ['century', 'decade', 'year', 'month'];
const allValueTypes = [...allViews.slice(1), 'day'];

export const isValueType = PropTypes.oneOf(allValueTypes);

export function isMinDate(props: Record<string, unknown>, propName: string, componentName: string) {
export const isMinDate: Validator<Date | undefined | null> = function isMinDate(
props,
propName,
componentName,
) {
const { [propName]: minDate } = props;

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

return null;
}
};

export function isMaxDate(props: Record<string, unknown>, propName: string, componentName: string) {
export const isMaxDate: Validator<Date | undefined | null> = function isMaxDate(
props,
propName,
componentName,
) {
const { [propName]: maxDate } = props;

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

return null;
}
};

export const isRef = PropTypes.oneOfType([
PropTypes.func,
Expand Down

0 comments on commit 1fe8d94

Please sign in to comment.