-
-
Notifications
You must be signed in to change notification settings - Fork 727
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
Make months and weekdays types slightly less restrictive #843
Conversation
Codecov Report
@@ Coverage Diff @@
## master #843 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 15 15
Lines 645 645
Branches 141 141
=====================================
Hits 645 645 Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #843 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 15 15
Lines 645 645
Branches 141 141
=====================================
Hits 645 645 Continue to review full report at Codecov.
|
type aliases would solve this. if you could say import { MonthsArray, DaysArray } from "react-day-picker";
const months: MonthsArray = [ ...12 type-safe strings ];
const weekdaysLong: DaysArray = [ ...7 type-safe strings ]; |
I hadn't thought about exposing the type aliases. It's still a bit annoying to have to explicitly declare the type or cast them though. Incidentally that's currently how I get around the problem - by declaring my own Playing around with it, it gives better type safety to this case (ts-playground) Personally I don't think it gives you very much in this instance, If I'm getting the month names from something else, like moment, I have to then cast anyway. (Or convince whatever 3rd party source I'm using to use the same typing convention). |
@johnjesse any updates on this PR? it is holding up another PR I made to blueprintjs about a month ago... Would need that merged sooner rather than later as I am using the component for an app that needs to go to production :( |
@sokmeann no updates I'm afraid, I'm not a maintainer of this library As a workaround I suggest you type you extract a type
or the same for weekdays |
Hey friends, sorry for being inactive the last months. Just trying to catch it up :) |
Awesome 😄 thank you! |
I think the typings for
months
,weekdaysLong
andweekdaysShort
are too strict. For instance, I get a type error from the followingbecause the inferred type of the months variable is
string[]
. Whilst the current typings formonths
,weekdaysLong
andweekdaysShort
are strictly true in requiring 12, 7 and 7 entries, typescript has difficulty in inferring those types and this makes them unwieldy to use in practice. I suggest loosening them slightly to besting[]
.