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

Type definition for dayjs incomplete #924

Closed
LarsKumbier opened this issue Jun 5, 2020 · 2 comments · Fixed by #951
Closed

Type definition for dayjs incomplete #924

LarsKumbier opened this issue Jun 5, 2020 · 2 comments · Fixed by #951
Labels

Comments

@LarsKumbier
Copy link

The type for daysjs() does not honor the functionality described in the string + format document, after loading the CustomParseFormat plugin.

The following ways of calling the daysjs() constructor are valid:

dayjs.extend(customParseFormat)
dayjs('1970-01-01', 'YYYY-MM-DD')  // (1) string format
dayjs('1970-01-01', 'YYYY-MM-DD', true) // (2) strict parsing
dayjs('1970-01-01', 'YYYY-MM-DD', 'de', true) // (3) strict parsing with locale
dayjs('1970-01-01', 'YYYY-MM-DD', 'de') // (4) permissive parsing with locale

However, the typescript type file only cover cases (1) and (4), but fail to consider cases (2) and (3):

// src: https://github.com/iamkun/dayjs/blob/dev/types/index.d.ts#L4
declare function dayjs (date?: dayjs.ConfigType, option?: dayjs.OptionType, locale?: string): dayjs.Dayjs

Workarounds

A workaround for case (2) is to cast the (supposed) locale-option to any:

dayjs('1970-01-01', 'YYYY-MM-DD', true as any)

Case (3) does not have a workaround, beside overwriting the types in a project-wide index.d.ts file.

@iamkun
Copy link
Owner

iamkun commented Jul 2, 2020

Thanks. Fixed.

@iamkun
Copy link
Owner

iamkun commented Jul 2, 2020

🎉 This issue has been resolved in version 1.8.29 🎉

The release is available on:

Your semantic-release bot 📦🚀

@iamkun iamkun added the released label Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants