Skip to content

Add d.ts for Intl.RelativeTimeFormat - #36084

Merged
Orta Therox (orta) merged 5 commits into
microsoft:masterfrom
DmitryMakhnev:master
May 20, 2020
Merged

Orta Therox (orta) merged 5 commits into
microsoft:masterfrom
DmitryMakhnev:master

Conversation

@DmitryMakhnev

Copy link
Copy Markdown
Contributor

Intl.RelativeTimeFormat proposal was moved to stage 4 and included into ecma402 finished proposals

Fixes part of #29129

@msftclas

Microsoft Contribution License Agreements (msftclas) commented Jan 8, 2020 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@orta

Copy link
Copy Markdown
Contributor

👋 hi, you submitted this just as we were preparing for a release, and we get really slow on 3rd party PRs during that period. We're now on 3.9 for master and I think this looks good. You're welcome to ping me on any Intl PRs you're looking at.

I've only got one request, can you consider adding some JSDoc comments to the user facing parts of the API?

@DmitryMakhnev

Dmitry Makhnev (DmitryMakhnev) commented Feb 11, 2020 •

Copy link
Copy Markdown
Contributor Author

👋Orta Therox (@orta)
Thank you so much for information! 🙏

Could you give me the rules for these JSDoc comments or link to example of it in the current code base?

@orta

Copy link
Copy Markdown
Contributor

There aren't any rules - it's just that you see these in your editor, and it's good to provide context for users. For example, I took some of the spec text and applied the useful bits of text to the prominent user-facing parts of the API

interface RelativeTimeFormat {
    /**
     * Formats a value and unit according to the locale and formatting options of this Intl.RelativeTimeFormat object.
     *
     * While this method automatically provides the correct plural forms, the grammatical form is otherwise as neutral as possible. It is the caller's responsibility to handle cut-off logic such as deciding between displaying "in 7 days" or "in 1 week". This API does not support relative dates involving compound units. e.g "in 5 days and 4 hours".
    */
    format(
        value: number,
        unit: RelativeTimeFormatUnit,
    ): string;

    /**
     *  A version of the format method which it returns an array of objects which represent "parts" of the object, separating the formatted number into its constituent parts and separating it from other surrounding text.
     */
    formatToParts(
        value: number,
        unit: RelativeTimeFormatUnit,
    ): RelativeTimeFormatPart[];
    
    resolvedOptions(): ResolvedRelativeTimeFormatOptions;
}

Screen Shot 2020-02-11 at 3 15 18 PM

@sandersn

Copy link
Copy Markdown
Member

This PR hasn't seen any activity for quite a while, so I'm going to close it to keep the number of open PRs manageable. Feel free to open a fresh PR or continue the discussion here.

@DmitryMakhnev

Dmitry Makhnev (DmitryMakhnev) commented May 10, 2020 •

Copy link
Copy Markdown
Contributor Author

Hi Nathan Shively-Sanders (@sandersn). Sorry for big delay. I added docs by Orta Therox (@orta)'s request.
Can you reopen this pull request?

@sandersn

Copy link
Copy Markdown
Member

Sure.

  1. Dmitry Makhnev (@DmitryMakhnev) can you merge with master to get rid of the merge conflict?
  2. Orta Therox (@orta) can you review the newly-added documentation?

@orta

Copy link
Copy Markdown
Contributor

These look great!

# Conflicts:
#	src/testRunner/unittests/config/commandLineParsing.ts

Conflicts were resolved
@DmitryMakhnev

Copy link
Copy Markdown
Contributor Author

Nathan Shively-Sanders (@sandersn)

  1. Dmitry Makhnev (@DmitryMakhnev) can you merge with master to get rid of the merge conflict?

Done.

@DmitryMakhnev

Copy link
Copy Markdown
Contributor Author

Nathan Shively-Sanders (@sandersn) Orta Therox (@orta)
Should I do anything else for this PR?

@orta

Copy link
Copy Markdown
Contributor

Nope, this is good to go! Thanks

@orta
Orta Therox (orta) merged commit dbaeed5 into microsoft:master May 20, 2020
@kripod

Copy link
Copy Markdown

Whoa, I just checked why Intl.RelativeTimeFormat was throwing an error on me and ended up at this issue right this time. Great job on getting this done, thank you! 🙏

AllenLee (cangSDARM) added a commit to cangSDARM/TypeScript that referenced this pull request May 21, 2020
* upstream/master:
  Make new error an error, not message
  fix(38299): use string literals as keys to creating rest result (microsoft#38600)
  Intersection check for empty object type shouldn't cause circularities (microsoft#38673)
  fix(38682): use stable typescript version (microsoft#38683)
  Add d.ts for Intl.RelativeTimeFormat (microsoft#36084)
  fix(38295): handle duplicate object literal keys which contain '+' and '-' tokens
  make last para of Actomics.notify optional.
  Fix some JSDoc factory function return types.
  fix order and tests
  move to invocationErrorDetails
  replace the original not-callable error
  Add _0_is_declared_here pointing to accessor declaration
  Better error message for accidental calls to get-accessors
@kwasimensah

Copy link
Copy Markdown

What's the ETA for this being in the published typescript npm package?

@sandersn

Copy link
Copy Markdown
Member

kwasimensah Should be 4.0. See #38510 for details.

@Licen-it

Copy link
Copy Markdown

kwasimensah Should be 4.0. See #38510 for details.

Nathan Shively-Sanders (@sandersn) any news on the ETA for having this published? Just checked latest version and it's still not there.

@barakplasma

Michael Salaverry (barakplasma) commented May 18, 2021 •

Copy link
Copy Markdown

Andrea Paolucci (@Licen-it)
It's in Typescript 4.0.5 - 4.2.3 already, but you have to update your tsconfig.json to target ES2020. Here's an example:

const timeFormatter = new Intl.RelativeTimeFormat(['en', 'fr', 'es', 'it', 'pt'], { numeric: 'always' });

Playground Link

@Licen-it

Copy link
Copy Markdown

Andrea Paolucci (@Licen-it)
It's in Typescript 4.0.5 - 4.2.3 already, but you have to update your tsconfig.json to target ES2020. Here's an example:

const timeFormatter = new Intl.RelativeTimeFormat(['en', 'fr', 'es', 'it', 'pt'], { numeric: 'always' });

Playground Link

Thanks...didn't think about changing the target in tsconfig. Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

8 participants