[luxon] Minor fixes and improvements#55443
[luxon] Minor fixes and improvements#55443typescript-bot merged 3 commits intoDefinitelyTyped:masterfrom hugofpsilva:master
Conversation
|
@hugofpsilva Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — I'm the local bot who will help you through the process of getting things through. This is a live comment which I will keep updated. 1 package in this PR
Code ReviewsBecause you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it. You can test the changes of this PR in the Playground. Status
All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 55443,
"author": "hugofpsilva",
"headCommitOid": "4c3db3e8b22bacbbcc6b8c80dcfff500276b0234",
"lastPushDate": "2021-08-29T17:26:07.000Z",
"lastActivityDate": "2021-08-29T19:49:50.000Z",
"mergeOfferDate": "2021-08-29T19:44:04.000Z",
"mergeRequestDate": "2021-08-29T19:49:50.000Z",
"mergeRequestUser": "hugofpsilva",
"hasMergeConflict": false,
"isFirstContribution": true,
"tooManyFiles": false,
"popularityLevel": "Popular",
"pkgInfo": [
{
"name": "luxon",
"kind": "edit",
"files": [
{
"path": "types/luxon/src/datetime.d.ts",
"kind": "definition"
},
{
"path": "types/luxon/test/luxon-tests.global.ts",
"kind": "test"
},
{
"path": "types/luxon/test/luxon-tests.module.ts",
"kind": "test"
}
],
"owners": [
"colbydehart",
"FourwingsY",
"jsiebern",
"mastermatt",
"pietrovismara",
"dawnmist",
"ycmjason",
"Aitor1995",
"peterblazejewicz",
"carsonf",
"hugofpsilva"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Popular"
}
],
"reviews": [
{
"type": "approved",
"reviewer": "peterblazejewicz",
"date": "2021-08-29T19:43:30.000Z",
"isMaintainer": true
}
],
"mainBotCommentID": 907598238,
"ciResult": "pass"
} |
|
🔔 @colbydehart @FourwingsY @jsiebern @mastermatt @pietrovismara @dawnmist @ycmjason @Aitor1995 @peterblazejewicz @CarsonF — please review this PR in the next few days. Be sure to explicitly select |
|
one topic at time, why those should be optional? Is that how the Luxon states this (in Docs)? |
|
You are again correct, the docs don't specify these arguments as optional. Then again, the docs aren't nearly 100% accurate. Just as a fast example, the local() documentation doesn't even mention the options object as a last parameter (but does show it in the examples). IMO Luxon is very permissive with the values passed to some (not all) of its methods. In the example you gave of I also added type tests for all the methods for which I marked the arguments as optional. Don't get me wrong, I agree with you that |
|
I agree with @peterblazejewicz here. Just because a JS library doesn't break with a certain input doesn't mean it's expected/"allowed". As you said, calling |
|
Alright it actually makes a lot more sense to me as it was, so I'm down for keeping it, I just thought it wasn't TS's job to restrict the user beyond typechecking. I'll roll back that part 😃 |
Marked several params as optional where Luxon doesn't throw errors. Fixed typing errors in ordinal getter, resolvedLocaleOptions, toLocaleString, toLocaleParts, and all DateTime format presets.
|
@peterblazejewicz Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review? |
|
Ready to merge |
|
I just published |
| export type DateTimeFormatPresetValue = 'numeric' | 'short' | 'long'; | ||
| export interface DateTimeFormatPreset { | ||
| year?: DateTimeFormatPresetValue; | ||
| month?: DateTimeFormatPresetValue; | ||
| day?: DateTimeFormatPresetValue; | ||
| weekday?: DateTimeFormatPresetValue; | ||
| hour?: DateTimeFormatPresetValue; | ||
| minute?: DateTimeFormatPresetValue; | ||
| second?: DateTimeFormatPresetValue; | ||
| timeZoneName?: DateTimeFormatPresetValue; | ||
| hourCycle?: 'h23'; | ||
| } |
There was a problem hiding this comment.
This type is inherently broken.
The type allows:
DateTime.fromISO("2021-09-13T07:52:27.697Z").toLocaleString({
...DateTime.DATETIME_MED,
hour: "short"
})But crashes at runtime. DateTimeFormatPresetValue does not apply for all options in DateTimeFormatPreset.
There was a problem hiding this comment.
It is not restrictive enough in some cases and too restrictive in others.
For example the following throws a type error but works correctly at runtime:
DateTime.fromISO("2021-09-13T07:52:27.697Z").toLocaleString({
...DateTime.DATETIME_MED,
hour: "2-digit"
})| * DateTime.now().toLocaleString({ hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }); //=> '11:32' | ||
| */ | ||
| toLocaleString(formatOpts?: DateTimeFormatOptions, opts?: LocaleOptions): string; | ||
| toLocaleString(formatOpts?: DateTimeFormatPreset | DateTimeFormatOptions, opts?: LocaleOptions): string; |
There was a problem hiding this comment.
Why was this type changed at all? Shouldn't the presets always be valid DateTimeFormatOptions as well?
There was a problem hiding this comment.
I believe the intent was to provide better typing for presets. I've read a book, the author rewrote ending 39 times, this applies to our code IMO
#55750
This adds proper support for constants used by date time for inputs. This change should also fix problems from comments in DefinitelyTyped#55443 `Formats` supports subset of Int.DateTimeFormatOptions types. Thanks!
…ort by @peterblazejewicz This adds proper support for constants used by date time for inputs. This change should also fix problems from comments in #55443 `Formats` supports subset of Int.DateTimeFormatOptions types. Thanks!
Luxon
DateTime
Added overloads for local() and utc(). (Are now necessary due to the object param after the number params).
Marked several params as optional where Luxon doesn't throw errors.
Fixed typing errors in ordinal getter, resolvedLocaleOptions, toLocaleString, toLocaleParts, and all format presets.
Please fill in this template.
npm test <package to test>.Select one of these and delete the others:
If changing an existing definition: