Skip to content

Commit

Permalink
Fix types to ensure calendarType is explicitly passed
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Oct 17, 2023
1 parent 746b966 commit 7cda6cb
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
12 changes: 8 additions & 4 deletions packages/react-calendar/src/MonthView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import WeekNumbers from './MonthView/WeekNumbers.js';
import { CALENDAR_TYPES, CALENDAR_TYPE_LOCALES } from './shared/const.js';
import { isCalendarType, tileGroupProps } from './shared/propTypes.js';

import type { CalendarType } from './shared/types.js';
import type { CalendarType, DeprecatedCalendarType } from './shared/types.js';

function getCalendarTypeFromLocale(locale: string | undefined): CalendarType {
if (locale) {
Expand All @@ -24,10 +24,14 @@ function getCalendarTypeFromLocale(locale: string | undefined): CalendarType {
}

type MonthViewProps = {
calendarType?: CalendarType | DeprecatedCalendarType;
showWeekNumbers?: boolean;
} & React.ComponentProps<typeof Weekdays> &
React.ComponentProps<typeof WeekNumbers> &
React.ComponentProps<typeof Days>;
} & Omit<
React.ComponentProps<typeof Weekdays> &
React.ComponentProps<typeof WeekNumbers> &
React.ComponentProps<typeof Days>,
'calendarType'
>;

const MonthView: React.FC<MonthViewProps> = function MonthView(props) {
const { activeStartDate, locale, onMouseLeave, showFixedNumberOfWeeks } = props;
Expand Down
3 changes: 2 additions & 1 deletion packages/react-calendar/src/MonthView/Day.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import Day from './Day.js';

const tileProps = {
activeStartDate: new Date(2018, 0, 1),
calendarType: 'iso8601',
classes: ['react-calendar__tile'],
currentMonthIndex: 0,
date: new Date(2018, 0, 1),
};
} satisfies React.ComponentProps<typeof Day>;

describe('Day', () => {
it('applies given classNames properly', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-calendar/src/MonthView/Day.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { CalendarType, DeprecatedCalendarType } from '../shared/types.js';
const className = 'react-calendar__month-view__days__day';

type DayProps = {
calendarType?: CalendarType | DeprecatedCalendarType;
calendarType: CalendarType | DeprecatedCalendarType | undefined;
classes?: string[];
currentMonthIndex: number;
formatDay?: typeof defaultFormatDay;
Expand Down
4 changes: 2 additions & 2 deletions packages/react-calendar/src/MonthView/Days.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { CalendarType, DeprecatedCalendarType } from '../shared/types.js';

type DaysProps = {
activeStartDate: Date;
calendarType?: CalendarType | DeprecatedCalendarType;
calendarType: CalendarType | DeprecatedCalendarType | undefined;
showFixedNumberOfWeeks?: boolean;
showNeighboringMonth?: boolean;
} & Omit<
Expand Down Expand Up @@ -89,8 +89,8 @@ export default function Days(props: DaysProps) {
key={date.getTime()}
{...otherProps}
{...otherTileProps}
calendarType={calendarType}
activeStartDate={activeStartDate}
calendarType={calendarTypeOrDeprecatedCalendarType}
currentMonthIndex={monthIndex}
date={date}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-calendar/src/MonthView/WeekNumbers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {

type WeekNumbersProps = {
activeStartDate: Date;
calendarType?: CalendarType | DeprecatedCalendarType;
calendarType: CalendarType | DeprecatedCalendarType | undefined;
onClickWeekNumber?: OnClickWeekNumberFunc;
onMouseLeave?: () => void;
showFixedNumberOfWeeks?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-calendar/src/MonthView/Weekdays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const className = 'react-calendar__month-view__weekdays';
const weekdayClassName = `${className}__weekday`;

type WeekdaysProps = {
calendarType?: CalendarType | DeprecatedCalendarType;
calendarType: CalendarType | DeprecatedCalendarType | undefined;
formatShortWeekday?: typeof defaultFormatShortWeekday;
formatWeekday?: typeof defaultFormatWeekday;
locale?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-calendar/src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const calendarTypeMap: Record<DeprecatedCalendarType, CalendarType> = {
};

function isDeprecatedCalendarType(
calendarType?: CalendarType | DeprecatedCalendarType,
calendarType: CalendarType | DeprecatedCalendarType | undefined,
): calendarType is DeprecatedCalendarType {
return calendarType !== undefined && calendarType in DEPRECATED_CALENDAR_TYPES;
}
Expand Down

0 comments on commit 7cda6cb

Please sign in to comment.