Skip to content

Commit d7c5b63

Browse files
committed
Fix isValueOrValueArray propType not working well with TypeScript
1 parent dfc0cda commit d7c5b63

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/DateRangePicker.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Fit from 'react-fit';
88

99
import DateInput from 'react-date-picker/dist/cjs/DateInput';
1010

11-
import { isMaxDate, isMinDate } from './shared/propTypes';
11+
import { isMaxDate, isMinDate, rangeOf } from './shared/propTypes';
1212

1313
import type { ClassName, CloseReason, Detail, LooseValue, OpenReason, Value } from './shared/types';
1414

@@ -454,7 +454,7 @@ export default function DateRangePicker(props: DateRangePickerProps) {
454454

455455
const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]);
456456

457-
const isValueOrValueArray = PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]);
457+
const isValueOrValueArray = PropTypes.oneOfType([isValue, rangeOf(isValue)]);
458458

459459
DateRangePicker.propTypes = {
460460
autoFocus: PropTypes.bool,

src/shared/propTypes.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { Validator } from 'prop-types';
1+
import PropTypes from 'prop-types';
2+
3+
import type { Requireable, Validator } from 'prop-types';
4+
import type { Range } from './types';
25

36
export const isMinDate: Validator<Date | undefined | null> = function isMinDate(
47
props,
@@ -55,3 +58,7 @@ export const isMaxDate: Validator<Date | undefined | null> = function isMaxDate(
5558

5659
return null;
5760
};
61+
62+
export const rangeOf = <T>(type: Requireable<T>): Requireable<Range<T>> => {
63+
return PropTypes.arrayOf(type) as Requireable<Range<T>>;
64+
};

src/shared/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type Range<T> = [T, T];
1+
export type Range<T> = [T, T];
22

33
export type ClassName = string | null | undefined | (string | null | undefined)[];
44

0 commit comments

Comments
 (0)