Skip to content

Bug: Wrong type for onSelect arguments when passing typed mode property #1570

Answered by gpbl
VitaliyR asked this question in Support
Discussion options

You must be logged in to vote

To close this discussion, you should use type guards, e.g.

import { DayPicker, type PropsMulti, type PropsSingle } from "react-day-picker";
import "react-day-picker/dist/style.css";

type AppProps = PropsSingle | PropsMulti;

// Type guard to check if props is for single mode
function isSingleMode(props: AppProps): props is PropsSingle {
  return props.mode === "single";
}

export default function App(props: AppProps) {
  return isSingleMode(props) ? (
    <DayPicker
      mode="single"
      selected={props.selected}
      showWeekNumber
      onSelect={props.onSelect}
    />
  ) : (
    <DayPicker
      mode="multiple"
      selected={props.selected}
      showWeekNumber
      onSelect={p…

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@VitaliyR
Comment options

@gpbl
Comment options

@VitaliyR
Comment options

@gpbl
Comment options

@VitaliyR
Comment options

Comment options

You must be logged in to vote
2 replies
@gpbl
Comment options

@owaisahmed5300
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by gpbl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #1569 on October 02, 2022 13:24.