Skip to content

chore: Explicit module boundary types #7764

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

Merged
merged 20 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export default [{
"rsp-rules/no-getByRole-toThrow": ERROR,
"rulesdir/imports": OFF,
"monorepo/no-internal-import": OFF,
"jsdoc/require-jsdoc": OFF,
"jsdoc/require-jsdoc": OFF
},

languageOptions: {
Expand Down Expand Up @@ -437,6 +437,29 @@ export default [{
"jsdoc/require-jsdoc": OFF,
"jsdoc/require-description": OFF,
},
}, {
files: [
"packages/**/*.ts",
"packages/**/*.tsx"
],

rules: {
"@typescript-eslint/explicit-module-boundary-types": ERROR,
},
}, {
files: [
"**/dev/**",
"**/test/**",
"**/stories/**",
"**/docs/**",
"**/chromatic/**",
"**/chromatic-fc/**",
"**/__tests__/**"
],

rules: {
"@typescript-eslint/explicit-module-boundary-types": OFF,
},
}, {
files: [
"packages/@react-aria/focus/src/**/*.ts",
Expand Down
28 changes: 14 additions & 14 deletions packages/@internationalized/date/src/CalendarDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,35 +155,35 @@ export class Time {
}

/** Returns a new `Time` with the given duration added to it. */
add(duration: TimeDuration) {
add(duration: TimeDuration): Time {
return addTime(this, duration);
}

/** Returns a new `Time` with the given duration subtracted from it. */
subtract(duration: TimeDuration) {
subtract(duration: TimeDuration): Time {
return subtractTime(this, duration);
}

/** Returns a new `Time` with the given fields set to the provided values. Other fields will be constrained accordingly. */
set(fields: TimeFields) {
set(fields: TimeFields): Time {
return setTime(this, fields);
}

/**
* Returns a new `Time` with the given field adjusted by a specified amount.
* When the resulting value reaches the limits of the field, it wraps around.
*/
cycle(field: TimeField, amount: number, options?: CycleTimeOptions) {
cycle(field: TimeField, amount: number, options?: CycleTimeOptions): Time {
return cycleTime(this, field, amount, options);
}

/** Converts the time to an ISO 8601 formatted string. */
toString() {
toString(): string {
return timeToString(this);
}

/** Compares this time with another. A negative result indicates that this time is before the given one, and a positive time indicates that it is after. */
compare(b: AnyTime) {
compare(b: AnyTime): number {
return compareTime(this, b);
}
}
Expand Down Expand Up @@ -361,45 +361,45 @@ export class ZonedDateTime {
}

/** Returns a new `ZonedDateTime` with the given duration added to it. */
add(duration: DateTimeDuration) {
add(duration: DateTimeDuration): ZonedDateTime {
return addZoned(this, duration);
}

/** Returns a new `ZonedDateTime` with the given duration subtracted from it. */
subtract(duration: DateTimeDuration) {
subtract(duration: DateTimeDuration): ZonedDateTime {
return subtractZoned(this, duration);
}

/** Returns a new `ZonedDateTime` with the given fields set to the provided values. Other fields will be constrained accordingly. */
set(fields: DateFields & TimeFields, disambiguation?: Disambiguation) {
set(fields: DateFields & TimeFields, disambiguation?: Disambiguation): ZonedDateTime {
return setZoned(this, fields, disambiguation);
}

/**
* Returns a new `ZonedDateTime` with the given field adjusted by a specified amount.
* When the resulting value reaches the limits of the field, it wraps around.
*/
cycle(field: DateField | TimeField, amount: number, options?: CycleTimeOptions) {
cycle(field: DateField | TimeField, amount: number, options?: CycleTimeOptions): ZonedDateTime {
return cycleZoned(this, field, amount, options);
}

/** Converts the date to a native JavaScript Date object. */
toDate() {
toDate(): Date {
return zonedToDate(this);
}

/** Converts the date to an ISO 8601 formatted string, including the UTC offset and time zone identifier. */
toString() {
toString(): string {
return zonedDateTimeToString(this);
}

/** Converts the date to an ISO 8601 formatted string in UTC. */
toAbsoluteString() {
toAbsoluteString(): string {
return this.toDate().toISOString();
}

/** Compares this date with another. A negative result indicates that this date is before the given one, and a positive date indicates that it is after. */
compare(b: CalendarDate | CalendarDateTime | ZonedDateTime) {
compare(b: CalendarDate | CalendarDateTime | ZonedDateTime): number {
// TODO: Is this a bad idea??
return this.toDate().getTime() - toZoned(b, this.timeZone).toDate().getTime();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ export class BuddhistCalendar extends GregorianCalendar {
);
}

toJulianDay(date: AnyCalendarDate) {
toJulianDay(date: AnyCalendarDate): number {
return super.toJulianDay(toGregorian(date));
}

getEras() {
getEras(): string[] {
return ['BE'];
}

getDaysInMonth(date: AnyCalendarDate): number {
return super.getDaysInMonth(toGregorian(date));
}

balanceDate() {}
balanceDate(): void {}
}

function toGregorian(date: AnyCalendarDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class EthiopicCalendar implements Calendar {
return new CalendarDate(this, era, year, month, day);
}

toJulianDay(date: AnyCalendarDate) {
toJulianDay(date: AnyCalendarDate): number {
let year = date.year;
if (date.era === 'AA') {
year -= AMETE_MIHRET_DELTA;
Expand Down Expand Up @@ -107,7 +107,7 @@ export class EthiopicCalendar implements Calendar {
return date.era === 'AA' ? 9999 : 9991;
}

getEras() {
getEras(): string[] {
return ['AA', 'AM'];
}
}
Expand All @@ -125,7 +125,7 @@ export class EthiopicAmeteAlemCalendar extends EthiopicCalendar {
return new CalendarDate(this, 'AA', year, month, day);
}

getEras() {
getEras(): string[] {
return ['AA'];
}

Expand Down Expand Up @@ -154,7 +154,7 @@ export class CopticCalendar extends EthiopicCalendar {
return new CalendarDate(this, era, year, month, day);
}

toJulianDay(date: AnyCalendarDate) {
toJulianDay(date: AnyCalendarDate): number {
let year = date.year;
if (date.era === 'BCE') {
year = 1 - year;
Expand All @@ -176,14 +176,14 @@ export class CopticCalendar extends EthiopicCalendar {
return date.era === 'BCE';
}

balanceDate(date: Mutable<AnyCalendarDate>) {
balanceDate(date: Mutable<AnyCalendarDate>): void {
if (date.year <= 0) {
date.era = date.era === 'BCE' ? 'CE' : 'BCE';
date.year = 1 - date.year;
}
}

getEras() {
getEras(): string[] {
return ['BCE', 'CE'];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ export class GregorianCalendar implements Calendar {
return 9999;
}

getEras() {
getEras(): string[] {
return ['BC', 'AD'];
}

isInverseEra(date: AnyCalendarDate): boolean {
return date.era === 'BC';
}

balanceDate(date: Mutable<AnyCalendarDate>) {
balanceDate(date: Mutable<AnyCalendarDate>): void {
if (date.year <= 0) {
date.era = date.era === 'BC' ? 'AD' : 'BC';
date.year = 1 - date.year;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class HebrewCalendar implements Calendar {
return new CalendarDate(this, year, month, day);
}

toJulianDay(date: AnyCalendarDate) {
toJulianDay(date: AnyCalendarDate): number {
let jd = startOfYear(date.year);
for (let month = 1; month < date.month; month++) {
jd += getDaysInMonth(date.year, month);
Expand All @@ -185,11 +185,11 @@ export class HebrewCalendar implements Calendar {
return 9999;
}

getEras() {
getEras(): string[] {
return ['AM'];
}

balanceYearMonth(date: Mutable<AnyCalendarDate>, previousDate: AnyCalendarDate) {
balanceYearMonth(date: Mutable<AnyCalendarDate>, previousDate: AnyCalendarDate): void {
// Keep date in the same month when switching between leap years and non leap years
if (previousDate.year !== date.year) {
if (isLeapYear(previousDate.year) && !isLeapYear(date.year) && previousDate.month > 6) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class IndianCalendar extends GregorianCalendar {
return new CalendarDate(this, indianYear, indianMonth, indianDay);
}

toJulianDay(date: AnyCalendarDate) {
toJulianDay(date: AnyCalendarDate): number {
let extendedYear = date.year + INDIAN_ERA_START;
let [era, year] = fromExtendedYear(extendedYear);

Expand Down Expand Up @@ -121,9 +121,9 @@ export class IndianCalendar extends GregorianCalendar {
return 9919;
}

getEras() {
getEras(): string[] {
return ['saka'];
}

balanceDate() {}
balanceDate(): void {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class IslamicCivilCalendar implements Calendar {
return julianDayToIslamic(this, CIVIL_EPOC, jd);
}

toJulianDay(date: AnyCalendarDate) {
toJulianDay(date: AnyCalendarDate): number {
return islamicToJulianDay(CIVIL_EPOC, date.year, date.month, date.day);
}

Expand All @@ -82,7 +82,7 @@ export class IslamicCivilCalendar implements Calendar {
return 9665;
}

getEras() {
getEras(): string[] {
return ['AH'];
}
}
Expand All @@ -101,7 +101,7 @@ export class IslamicTabularCalendar extends IslamicCivilCalendar {
return julianDayToIslamic(this, ASTRONOMICAL_EPOC, jd);
}

toJulianDay(date: AnyCalendarDate) {
toJulianDay(date: AnyCalendarDate): number {
return islamicToJulianDay(ASTRONOMICAL_EPOC, date.year, date.month, date.day);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ export class JapaneseCalendar extends GregorianCalendar {
);
}

toJulianDay(date: AnyCalendarDate) {
toJulianDay(date: AnyCalendarDate): number {
return super.toJulianDay(toGregorian(date));
}

balanceDate(date: Mutable<AnyCalendarDate>) {
balanceDate(date: Mutable<AnyCalendarDate>): void {
let gregorianDate = toGregorian(date);
let era = findEraFromGregorianDate(gregorianDate);

Expand All @@ -102,7 +102,7 @@ export class JapaneseCalendar extends GregorianCalendar {
this.constrainDate(date);
}

constrainDate(date: Mutable<AnyCalendarDate>) {
constrainDate(date: Mutable<AnyCalendarDate>): void {
let idx = ERA_NAMES.indexOf(date.era);
let end = ERA_END_DATES[idx];
if (end != null) {
Expand Down Expand Up @@ -131,7 +131,7 @@ export class JapaneseCalendar extends GregorianCalendar {
}
}

getEras() {
getEras(): string[] {
return ERA_NAMES;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class PersianCalendar implements Calendar {
return isLeapYear ? 30 : 29;
}

getEras() {
getEras(): string[] {
return ['AP'];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ export class TaiwanCalendar extends GregorianCalendar {
return new CalendarDate(this, era, year, date.month, date.day);
}

toJulianDay(date: AnyCalendarDate) {
toJulianDay(date: AnyCalendarDate): number {
return super.toJulianDay(toGregorian(date));
}

getEras() {
getEras(): string[] {
return ['before_minguo', 'minguo'];
}

balanceDate(date: Mutable<AnyCalendarDate>) {
balanceDate(date: Mutable<AnyCalendarDate>): void {
let [era, year] = gregorianToTaiwan(gregorianYear(date));
date.era = era;
date.year = year;
Expand Down
8 changes: 4 additions & 4 deletions packages/@internationalized/date/src/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import {getExtendedYear, GregorianCalendar} from './calendars/GregorianCalendar'
import {getLocalTimeZone} from './queries';
import {Mutable} from './utils';

export function epochFromDate(date: AnyDateTime) {
export function epochFromDate(date: AnyDateTime): number {
date = toCalendar(date, new GregorianCalendar());
let year = getExtendedYear(date.era, date.year);
return epochFromParts(year, date.month, date.day, date.hour, date.minute, date.second, date.millisecond);
}

function epochFromParts(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number) {
function epochFromParts(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number): number {
// Note: Date.UTC() interprets one and two-digit years as being in the
// 20th century, so don't use it
let date = new Date();
Expand All @@ -35,7 +35,7 @@ function epochFromParts(year: number, month: number, day: number, hour: number,
return date.getTime();
}

export function getTimeZoneOffset(ms: number, timeZone: string) {
export function getTimeZoneOffset(ms: number, timeZone: string): number {
// Fast path for UTC.
if (timeZone === 'UTC') {
return 0;
Expand Down Expand Up @@ -292,7 +292,7 @@ export function toZoned(date: CalendarDate | CalendarDateTime | ZonedDateTime, t
return fromAbsolute(ms, timeZone);
}

export function zonedToDate(date: ZonedDateTime) {
export function zonedToDate(date: ZonedDateTime): Date {
let ms = epochFromDate(date) - date.offset;
return new Date(ms);
}
Expand Down
Loading