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

Update bigint declaration file #38526

Merged
merged 12 commits into from
Jun 22, 2020

Conversation

ShuiRuTian
Copy link
Contributor

Fixes #36970

@Kingwl Kingwl mentioned this pull request May 13, 2020
@sandersn sandersn requested review from sandersn and orta May 20, 2020 17:50
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs to make NumberFormat.format support bigint in order to fix #36970.

/**
* The locale matching algorithm to use.The default is "best fit". For information about this option, see the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation Intl page}.
*/
localeMatcher?: "lookup" | "best fit" | string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"x" | string is currently reduced to string and the literals are thrown out. I think string is fine for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature request for supporting this is #33471

Copy link
Contributor Author

@ShuiRuTian ShuiRuTian May 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need to remove these "x", or just leave them here, waiting for the benefit of this feature request?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a fairly complex feature and not likely to be in 4.0 or 4.1. We should stick with string for all these unions.

}

interface BigIntToLocaleStringOptionsStyleUnit extends Omit<BigIntToLocaleStringOptionsBase, "style"> {
style: "unit";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All you get for the overhead of these two interfaces+union is the ability to make unit appear only when style: "unit". Considering that every other field in BigIntToLocaleStringOptionsBase is optional, I think it's better to put both unit and currency in the base as optional too, then get rid of the subtypes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.
In fact, "unit" and "currency" are already in base class as optional.
I would like to use "unit" as example to explain why I did this:
If "style" is not "unit", the value of "unit" is arbitrary, but if "style" is "unit" and "unit" is undefined, there would be an error. With this, user could know the error while type checking.
So which side does the responsibility to avoid error belongs to? The user-side or ts-definition?
I prefer latter one, but both are reasonable.
Anyway, I would follow your final decision.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tradeoff is that the standard library is more complicated and slower to check. I'd like to go with the simpler single-interface solution and let users avoid the error.

@sandersn sandersn self-assigned this May 20, 2020
@sandersn sandersn added the For Backlog Bug PRs that fix a backlog bug label May 20, 2020
@ShuiRuTian ShuiRuTian requested a review from sandersn May 25, 2020 05:17
@ShuiRuTian
Copy link
Contributor Author

Friendly ping @sandersn ~

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs to make NumberFormat.format support bigint in order to fix #36970.

/**
* The locale matching algorithm to use.The default is "best fit". For information about this option, see the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation Intl page}.
*/
localeMatcher?: "lookup" | "best fit" | string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a fairly complex feature and not likely to be in 4.0 or 4.1. We should stick with string for all these unions.

}

interface BigIntToLocaleStringOptionsStyleUnit extends Omit<BigIntToLocaleStringOptionsBase, "style"> {
style: "unit";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tradeoff is that the standard library is more complicated and slower to check. I'd like to go with the simpler single-interface solution and let users avoid the error.

@sandersn sandersn merged commit d76e85d into microsoft:master Jun 22, 2020
@sandersn
Copy link
Member

Thanks for the PR, @ShuiRuTian!

cangSDARM added a commit to cangSDARM/TypeScript that referenced this pull request Jun 23, 2020
* upstream/master: (58 commits)
  Variadic tuple types (microsoft#39094)
  chore: resolve suggestions
  Expand auto-import to all package.json dependencies (microsoft#38923)
  inline local functions
  Update bigint declaration file (microsoft#38526)
  Update user baselines (microsoft#39077)
  LEGO: check in for master to temporary branch.
  Add missing index.ts files to user projects (microsoft#39163)
  Add reason for a disabled code action (microsoft#37871)
  Minor fix for assertion predicates (microsoft#38710)
  Update LKG (microsoft#39173)
  Reparse top level 'await' in modules (microsoft#39084)
  change
  chore: more change
  chore: resolve review
  chore: save space
  fix: lint error
  test: add test for it
  chore: make isJsxAttr required
  chore: revert change in checker
  ...

# Conflicts:
#	src/compiler/binder.ts
#	src/compiler/checker.ts
#	src/compiler/parser.ts
#	src/compiler/types.ts
Jack-Works pushed a commit to Jack-Works/TypeScript that referenced this pull request Jun 24, 2020
* update toLocalString function signature

* update test.

* fix lint

* follow review advice.

* format and better comment.

* format

* add case

* fix symbol.

* remove subtype and string union in interface.

* remove useless code.

Co-authored-by: Song Gao <song.gao@laserfiche.com>
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
Archived in project
Development

Successfully merging this pull request may close these issues.

BigInt.toLocaleString does not have any arguments, and Intl.NumberFormat does not support formatting BigInt
4 participants