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 38fe9e1 commit dfc0cda
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,4 +1,10 @@
export function isMinDate(props: Record<string, unknown>, propName: string, componentName: string) {
import type { Validator } from 'prop-types';

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

if (!minDate) {
Expand All @@ -20,9 +26,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 @@ -44,4 +54,4 @@ export function isMaxDate(props: Record<string, unknown>, propName: string, comp
}

return null;
}
};

0 comments on commit dfc0cda

Please sign in to comment.