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 10fcd92
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/react-calendar/src/MonthView.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { format } = new Intl.DateTimeFormat('en-US', {
describe('MonthView', () => {
const defaultProps = {
activeStartDate: new Date(2017, 0, 1),
calendarType: 'iso8601',
valueType: 'day',
} satisfies React.ComponentProps<typeof MonthView>;

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 10fcd92

Please sign in to comment.