Skip to content
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

Export function declarations from LocaleData Plugin #1116

Merged
merged 3 commits into from
Oct 14, 2020
Merged
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion types/plugin/localeData.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,14 @@ export = plugin
declare module 'dayjs' {
interface Dayjs {
localeData(): any
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean under interface Dayjs?

If so, I think the exported functions should not sit under the interface since those functions are not instance methods of Dayjs.

Instead, those functions are like static, not binding to a class.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can typescript knows that weekdaysMin is available on dayjs like this dayjs.weekdaysMin()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because those functions are exported from module 'dayjs', which has nothing to do with interface Dayjs.

Screen Shot 2020-10-08 at 10 38 42 am

just like MinMax plugin

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, should we take dayjs().localeData().weekdays() into consideration as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. I've added localeData types to both dayjs and Dayjs instances.

Now (dayjs or dayjs()).localeData() both have types.

}
}

type DayNamesTuple = [string, string, string, string, string, string, string];
type MonthNamesTuple = [string, string, string, string, string, string, string, string, string, string, string, string];

export function weekdays(): DayNamesTuple;
export function weekdaysShort(): DayNamesTuple;
export function weekdaysMin(): DayNamesTuple;
export function monthsShort(): MonthNamesTuple;
export function months(): MonthNamesTuple;
}