Skip to content

Update bigint declaration file - #38526

Merged
Nathan Shively-Sanders (sandersn) merged 12 commits into
microsoft:masterfrom
ShuiRuTian:update-bigint-declaration-file
Jun 22, 2020
Merged

Update bigint declaration file#38526
Nathan Shively-Sanders (sandersn) merged 12 commits into
microsoft:masterfrom
ShuiRuTian:update-bigint-declaration-file

Conversation

@ShuiRuTian

Copy link
Copy Markdown
Contributor

Fixes#36970

@KingwlWenlu Wang (Kingwl) mentioned this pull request May 13, 2020

Copy link
Copy Markdown
Member

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.

Comment threadsrc/lib/es2020.bigint.d.ts Outdated
Comment threadsrc/lib/es2020.bigint.d.ts Outdated
/**
* 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
Copy Markdown
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
Copy Markdown
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

@ShuiRuTianSong Gao (ShuiRuTian)May 22, 2020

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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.

Comment threadsrc/lib/es2020.bigint.d.ts Outdated
}

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

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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.

Comment threadsrc/lib/es2020.bigint.d.ts Outdated
@ShuiRuTian

Copy link
Copy Markdown
ContributorAuthor

Friendly ping Nathan Shively-Sanders (@sandersn) ~

Copy link
Copy Markdown
Member

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.

Comment threadsrc/lib/es2020.bigint.d.ts Outdated
/**
* 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
Copy Markdown
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.

Comment threadsrc/lib/es2020.bigint.d.ts Outdated
}

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

Copy link
Copy Markdown
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
Nathan Shively-Sanders (sandersn) merged commit d76e85d into microsoft:masterJun 22, 2020
@sandersn

Copy link
Copy Markdown
Member

Thanks for the PR, Song Gao (@ShuiRuTian)!

AllenLee (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 (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>
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog BugPRs 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

@ShuiRuTian@sandersn@orta@RyanCavanaugh