Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected typing for RangerModifier #1065

Merged
merged 1 commit into from
Feb 12, 2021
Merged

Corrected typing for RangerModifier #1065

merged 1 commit into from
Feb 12, 2021

Conversation

joebenn
Copy link

@joebenn joebenn commented Oct 9, 2020

Came across a typing issue when using react-day-picker in our Typescript project.

Specifically, making use of the util function addDayToRange. The typing for addDayToRange is defined as:
addDayToRange(day: Date, range: RangeModifier): RangeModifier;.
where export interface RangeModifier { from: Date; to: Date; }

However the function addDayToRange, implemented in DateUtils.jsexpects (and handles) null date objects (from and to) objects, which contradicts the current typing for RangeModifier

I simply changed the typing to allow for the dates to be undefined within the RangeModifier object, and this solved the typing issues we were experiencing.

I also noticed RangeModifier was defined twice, so I removed the duplicate.

Cheers!

@elvorad
Copy link

elvorad commented Oct 22, 2020

I have the same TypeScript issue and would like to use the change that joebenn has requested – thank you for reaching in this merge request, joebenn! Dear maintainers, would somebody of you please be so kind as to approve this merge request and release a new version?

The tutorial site found under http://react-day-picker.js.org/examples/selected-range has an example in which from and to are set to undefined, yet the current type definition does not support this use case and throws false positives.

Comment on lines +2 to +3
from: Date | undefined;
to: Date | undefined;
Copy link

@mhaidamashko mhaidamashko Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want set undefined to interface property better to use ? if it's possible.

export interface RangeModifier {
  from?: Date;
  to?: Date;
}

Nevertheless, I think there should be

export interface RangeModifier {
  from?: Date | null;
  to?: Date | null;
}

Because In realisation of the function addDayToRange it has fallback to nulls.

export function addDayToRange(day, range = { from: null, to: null }) {}

@gpbl gpbl merged commit 78b1d12 into gpbl:v7 Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants