-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Add the type of Intl.DurationFormat to the lib. #60646
Open
developer-bandi
wants to merge
5
commits into
microsoft:main
Choose a base branch
from
developer-bandi:feat/intl-DurationFormat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+167
−2
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,168 @@ | ||||||||
declare namespace Intl { | ||||||||
// Empty | ||||||||
|
||||||||
/** | ||||||||
* Value of the `unit` property in duration objects | ||||||||
* | ||||||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration). | ||||||||
*/ | ||||||||
type DurationTimeFormatUnit = "years"|"months"|"weeks"|"days"|"hours"|"minutes"|"seconds"|"milliseconds"|"microseconds"|"nanoseconds" | ||||||||
|
||||||||
/** | ||||||||
* The style of the formatted duration. | ||||||||
* | ||||||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style). | ||||||||
*/ | ||||||||
type DurationFormatStyle = "long" | "short" | "narrow" | "digital" | ||||||||
|
||||||||
|
||||||||
type DurationFormatUnitSingular = | ||||||||
| "year" | ||||||||
| "quarter" | ||||||||
| "month" | ||||||||
| "week" | ||||||||
| "day" | ||||||||
| "hour" | ||||||||
| "minute" | ||||||||
| "second"; | ||||||||
|
||||||||
/** | ||||||||
* An object representing the relative time format in parts | ||||||||
* that can be used for custom locale-aware formatting. | ||||||||
* | ||||||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#examples). | ||||||||
*/ | ||||||||
type DurationFormatPart = | ||||||||
| { | ||||||||
type: "literal"; | ||||||||
value: string; | ||||||||
} | ||||||||
| { | ||||||||
type: Exclude<NumberFormatPartTypes, "literal">; | ||||||||
value: string; | ||||||||
unit: DurationFormatUnitSingular; | ||||||||
}; | ||||||||
|
||||||||
|
||||||||
|
||||||||
type DurationFormatOptions = "long"|"short"|"narrow"|"numeric"|"2-digit" | ||||||||
|
||||||||
|
||||||||
type DurationFormatDisplayOption = "always"|"auto"; | ||||||||
|
||||||||
/** | ||||||||
* Number of how many fractional second digits to display in the output. | ||||||||
* | ||||||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#fractionaldigits). | ||||||||
*/ | ||||||||
type fractionalDigitsOption = 0|1|2|3|4|5|6|7|8|9 | ||||||||
|
||||||||
interface ResolvedDurationFormatOptions { | ||||||||
locale?: UnicodeBCP47LocaleIdentifier | ||||||||
numberingSystem?: DateTimeFormatOptions["numberingSystem"] | ||||||||
style?: DurationFormatStyle | ||||||||
years?: Omit<DurationFormatOptions,"numeric"|"2-digit"> | ||||||||
yearsDisplay?:DurationFormatDisplayOption | ||||||||
months?: Omit<DurationFormatOptions,"numeric"|"2-digit"> | ||||||||
monthsDisplay?: DurationFormatDisplayOption | ||||||||
weeks?: Omit<DurationFormatOptions,"numeric"|"2-digit"> | ||||||||
weeksDisplay?: DurationFormatDisplayOption | ||||||||
days?: Omit<DurationFormatOptions,"numeric"|"2-digit"> | ||||||||
daysDisplay?: DurationFormatDisplayOption | ||||||||
hours?: DurationFormatOptions | ||||||||
hoursDisplay?: DurationFormatDisplayOption | ||||||||
minutes?: DurationFormatOptions | ||||||||
minutesDisplay?: DurationFormatDisplayOption | ||||||||
seconds?: DurationFormatOptions | ||||||||
secondsDisplay?: DurationFormatDisplayOption | ||||||||
milliseconds?: DurationFormatOptions | ||||||||
millisecondsDisplay?: DurationFormatDisplayOption | ||||||||
microseconds?: DurationFormatOptions | ||||||||
microsecondsDisplay?: DurationFormatDisplayOption | ||||||||
nanosecond?: DurationFormatOptions | ||||||||
nanosecondDisplay?: DurationFormatDisplayOption | ||||||||
fractionalDigits?: fractionalDigitsOption | ||||||||
} | ||||||||
|
||||||||
interface DurationFormatOptions { | ||||||||
localeMatcher?: LocaleMatcher | ||||||||
numberingSystem?: DateTimeFormatOptions["numberingSystem"] | ||||||||
style?: DurationFormatStyle | ||||||||
years?: Omit<DurationFormatOptions,"numeric"|"2-digit"> | ||||||||
yearsDisplay?:DurationFormatDisplayOption | ||||||||
months?: Omit<DurationFormatOptions,"numeric"|"2-digit"> | ||||||||
monthsDisplay?: DurationFormatDisplayOption | ||||||||
weeks?: Omit<DurationFormatOptions,"numeric"|"2-digit"> | ||||||||
weeksDisplay?: DurationFormatDisplayOption | ||||||||
days?: Omit<DurationFormatOptions,"numeric"|"2-digit"> | ||||||||
daysDisplay?: DurationFormatDisplayOption | ||||||||
hours?: DurationFormatOptions | ||||||||
hoursDisplay?: DurationFormatDisplayOption | ||||||||
minutes?: DurationFormatOptions | ||||||||
minutesDisplay?: DurationFormatDisplayOption | ||||||||
seconds?: DurationFormatOptions | ||||||||
secondsDisplay?: DurationFormatDisplayOption | ||||||||
milliseconds?: DurationFormatOptions | ||||||||
millisecondsDisplay?: DurationFormatDisplayOption | ||||||||
microseconds?: DurationFormatOptions | ||||||||
microsecondsDisplay?: DurationFormatDisplayOption | ||||||||
nanosecond?: DurationFormatOptions | ||||||||
nanosecondDisplay?: DurationFormatDisplayOption | ||||||||
fractionalDigits?: fractionalDigitsOption | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* The duration object to be formatted | ||||||||
* | ||||||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration). | ||||||||
*/ | ||||||||
type DurationType = Record<DurationTimeFormatUnit,number> | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tried this locally but with strict type settings this causes all fields to be required. I believe it is valid for the type to be partial, like
Suggested change
|
||||||||
|
||||||||
interface DurationFormat { | ||||||||
/** | ||||||||
* @param duration The duration object to be formatted. It should include some or all of the following properties: months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds. | ||||||||
* | ||||||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format). | ||||||||
*/ | ||||||||
format(duration: DurationType): string; | ||||||||
/** | ||||||||
* @param duration The duration object to be formatted. It should include some or all of the following properties: months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds. | ||||||||
* | ||||||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts). | ||||||||
*/ | ||||||||
formatToParts(duration: DurationType): DurationFormatPart[]; | ||||||||
/** | ||||||||
* [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions). | ||||||||
*/ | ||||||||
resolvedOptions(): ResolvedDurationFormatOptions; | ||||||||
} | ||||||||
|
||||||||
const DurationFormat: { | ||||||||
prototype: DurationFormat; | ||||||||
|
||||||||
/** | ||||||||
* @param locales A string with a BCP 47 language tag, or an array of such strings. | ||||||||
* For the general form and interpretation of the `locales` argument, see the [Intl](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation) | ||||||||
* page. | ||||||||
* | ||||||||
* @param options An object for setting up a duration format. | ||||||||
* | ||||||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat). | ||||||||
*/ | ||||||||
new (locales: LocalesArgument, options: DurationFormatOptions): DurationFormat; | ||||||||
|
||||||||
/** | ||||||||
* Returns an array containing those of the provided locales that are supported in display names without having to fall back to the runtime's default locale. | ||||||||
* | ||||||||
* @param locales A string with a BCP 47 language tag, or an array of such strings. | ||||||||
* For the general form and interpretation of the `locales` argument, see the [Intl](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation) | ||||||||
* page. | ||||||||
* | ||||||||
* @param options An object with a locale matcher. | ||||||||
* | ||||||||
* @returns An array of strings representing a subset of the given locale tags that are supported in display names without having to fall back to the runtime's default locale. | ||||||||
* | ||||||||
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf). | ||||||||
*/ | ||||||||
supportedLocalesOf(locales?: LocalesArgument, options?: { localeMatcher?: LocaleMatcher; }): UnicodeBCP47LocaleIdentifier[]; | ||||||||
}; | ||||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type must not be renamed, as that would be a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All existing type modifications were returned, and only cases where the existing type name was not applied were left. If there are any issues with this item, I will reinstate it.