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

Add d.ts for Intl.RelativeTimeFormat #36084

Merged
merged 5 commits into from
May 20, 2020
Merged

Conversation

DmitryMakhnev
Copy link
Contributor

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

Fixes part of #29129

@msftclas
Copy link

msftclas commented Jan 8, 2020

CLA assistant check
All CLA requirements met.

@sandersn sandersn added this to Curio in Pall Mall Jan 30, 2020
@sandersn sandersn added this to In progress in PR Backlog Feb 3, 2020
@sandersn sandersn added the For Backlog Bug PRs that fix a backlog bug label Feb 3, 2020
@orta orta self-assigned this Feb 11, 2020
@orta
Copy link
Contributor

orta commented Feb 11, 2020

👋 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
Copy link
Contributor Author

DmitryMakhnev commented Feb 11, 2020

👋@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
Contributor

orta commented Feb 11, 2020

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 sandersn removed this from Curio in Pall Mall Mar 9, 2020
@sandersn sandersn moved this from Not started to Waiting on author in PR Backlog Mar 9, 2020
@sandersn
Copy link
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.

@sandersn sandersn closed this Mar 11, 2020
PR Backlog automation moved this from Waiting on author to Done Mar 11, 2020
@DmitryMakhnev
Copy link
Contributor Author

DmitryMakhnev commented May 10, 2020

Hi @sandersn. Sorry for big delay. I added docs by @orta's request.
Can you reopen this pull request?

@sandersn sandersn reopened this May 11, 2020
PR Backlog automation moved this from Done to Not started May 11, 2020
@sandersn sandersn moved this from Not started to Needs merge in PR Backlog May 11, 2020
@sandersn
Copy link
Member

Sure.

  1. @DmitryMakhnev can you merge with master to get rid of the merge conflict?
  2. @orta can you review the newly-added documentation?

@orta
Copy link
Contributor

orta commented May 11, 2020

These look great!

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

Conflicts were resolved
@DmitryMakhnev
Copy link
Contributor Author

@sandersn

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

Done.

@DmitryMakhnev
Copy link
Contributor Author

@sandersn @orta
Should I do anything else for this PR?

@orta
Copy link
Contributor

orta commented May 20, 2020

Nope, this is good to go! Thanks

@orta orta merged commit dbaeed5 into microsoft:master May 20, 2020
PR Backlog automation moved this from Needs merge to Done May 20, 2020
@kripod
Copy link

kripod commented May 20, 2020

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! 🙏

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

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

@sandersn
Copy link
Member

@kwasimensah Should be 4.0. See #38510 for details.

@Licen-it
Copy link

@kwasimensah Should be 4.0. See #38510 for details.

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

@barakplasma
Copy link

barakplasma commented May 18, 2021

@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

@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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

8 participants