-
Bug descriptionBug with types for the react-day-picker To reproducehttps://codesandbox.io/s/react-daypicker-forked-wdgtko?file=/src/App.tsx StepsWrite the code Expected behaviorFor this case argument ScreenshotsAdditional contextI assume this happens as |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
Hey thanks for reporting this, I see some issues as well but I'm not sure if they are related to the discriminated union. Will investigate... |
Beta Was this translation helpful? Give feedback.
-
This should fix it: #1571 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
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={props.onSelect}
/>
);
} |
Beta Was this translation helpful? Give feedback.
To close this discussion, you should use type guards, e.g.