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 support for new type: bigint #6639

Closed
dnalborczyk opened this issue Jul 25, 2018 · 8 comments
Closed

add support for new type: bigint #6639

dnalborczyk opened this issue Jul 25, 2018 · 8 comments

Comments

@dnalborczyk
Copy link
Contributor

dnalborczyk commented Jul 25, 2018

(1n: bigint)

https://flow.org/try/#0BQRgdgXABARglgczmALgSiA

@goodmind goodmind added feature request parsing Library definitions Issues or pull requests about core library definitions Has PR labels Feb 13, 2019
@goodmind
Copy link
Contributor

goodmind commented Mar 19, 2019

Parsing side of this feature was imported in #7471.
Only typechecking remains.

facebook-github-bot pushed a commit that referenced this issue Mar 29, 2019
Summary:
<!--
  If this is a change to library defintions, please include links to relevant documentation.
  If this is a documentation change, please prefix the title with [DOCS].

  If this is neither, ensure you opened a discussion issue and link it in the PR description.
-->

Proposal: https://github.com/tc39/proposal-bigint
Discussion: #6639

This probably can be discussion?

Also `typeof` should support `bigint` but I don't know how to add it

Parsing errors:
![image](https://user-images.githubusercontent.com/3275424/52748292-f54ed780-3007-11e9-9185-bd1446dfb357.png)

Type errors:
![image](https://user-images.githubusercontent.com/3275424/52748417-4959bc00-3008-11e9-887f-c1a7a1e3f9da.png)
Pull Request resolved: #7471

Reviewed By: nmote

Differential Revision: D14524589

Pulled By: gabelevi

fbshipit-source-id: bc8f4a970f60259dd1dcd1a3c92f0a51f0aadfeb
@goodmind goodmind added Typing: other and removed Has PR parsing Library definitions Issues or pull requests about core library definitions labels Mar 29, 2019
@dsainati1
Copy link
Contributor

This should be resolved, so I'm going to close this.

@goodmind
Copy link
Contributor

goodmind commented Mar 29, 2019

@dsainati1 there is still typechecking part, only parsing was implemented

@id-ekaagr
Copy link

When can we expect this?

teamdandelion added a commit to sourcecred/sourcecred that referenced this issue Mar 7, 2020
This commit adds a `grain/grain.js` module, which contains a type and
logic for representing Grain balances with 18 digits of precision. We
use the native BigInt type (and add the necessary babel plugin to
support it).

Unfortunately, Flow does not yet support BigInts (see
[facebook/flow#6639]). To hack around this, we lie to Flow, claiming
that BigInts are numbers, and we expect/suppress the flow errors
whenever we actually instantiate one. For example:

```js
// $ExpectFlowError
const myBigInt = 5n;
```

We can use the BigInt operators like `+`, `-`, `>` without flow errors,
since these actually exist on numbers too. However, flow will fail to
detect improper combinations of regular numbers and BigInts:

```js
// $ExpectFlowError
const x = 5n;
const y = x + 5;
// Uncaught TypeError: Cannot mix BigInt and other types
```

Since any improper mixing will result in a runtime error, these issues
will be easy to detect via unit tests.

In addition to adding hte basic Grain type, I exported a `format`
function which will display Grain balances in a human readable way (i.e.
stripping most of the precision). This is both a useful method, and an
example of how to use the Grain type and work around flow issues.

Test plan: See included unit tests. `yarn test` passes.

[facebook/flow#6639]: facebook/flow#6639
teamdandelion added a commit to sourcecred/sourcecred that referenced this issue Mar 8, 2020
This commit adds a `grain/grain.js` module, which contains a type and
logic for representing Grain balances with 18 digits of precision. We
use the native BigInt type (and add the necessary babel plugin to
support it).

Unfortunately, Flow does not yet support BigInts (see
[facebook/flow#6639]). To hack around this, we lie to Flow, claiming
that BigInts are numbers, and we expect/suppress the flow errors
whenever we actually instantiate one. For example:

```js
// $ExpectFlowError
const myBigInt = 5n;
```

We can use the BigInt operators like `+`, `-`, `>` without flow errors,
since these actually exist on numbers too. However, flow will fail to
detect improper combinations of regular numbers and BigInts:

```js
// $ExpectFlowError
const x = 5n;
const y = x + 5;
// Uncaught TypeError: Cannot mix BigInt and other types
```

Since any improper mixing will result in a runtime error, these issues
will be easy to detect via unit tests.

In addition to adding the basic Grain type, I exported a `format`
function which will display Grain balances in a human readable way (i.e.
stripping most of the precision). This is both a useful method, and an
example of how to use the Grain type and work around flow issues.

Test plan: See included unit tests. `yarn test` passes.

[facebook/flow#6639]: facebook/flow#6639

Thanks to @Beanow and @HammadJ and @burrrata for feedback on
how much decimal precision to use.
teamdandelion added a commit to sourcecred/sourcecred that referenced this issue Mar 10, 2020
This commit adds a `grain/grain.js` module, which contains a type and
logic for representing Grain balances with 18 digits of precision. We
use the native BigInt type (and add the necessary babel plugin to
support it).

Unfortunately, Flow does not yet support BigInts (see
[facebook/flow#6639]). To hack around this, we lie to Flow, claiming
that BigInts are numbers, and we expect/suppress the flow errors
whenever we actually instantiate one. For example:

```js
// $ExpectFlowError
const myBigInt = 5n;
```

We can use the BigInt operators like `+`, `-`, `>` without flow errors,
since these actually exist on numbers too. However, flow will fail to
detect improper combinations of regular numbers and BigInts:

```js
// $ExpectFlowError
const x = 5n;
const y = x + 5;
// Uncaught TypeError: Cannot mix BigInt and other types
```

Since any improper mixing will result in a runtime error, these issues
will be easy to detect via unit tests.

In addition to adding the basic Grain type, I exported a `format`
function which will display Grain balances in a human readable way (i.e.
stripping most of the precision). This is both a useful method, and an
example of how to use the Grain type and work around flow issues.

Test plan: See included unit tests. `yarn test` passes.

[facebook/flow#6639]: facebook/flow#6639

Thanks to @Beanow and @HammadJ and @burrrata for feedback on
how much decimal precision to use.
teamdandelion added a commit to sourcecred/sourcecred that referenced this issue Mar 14, 2020
This commit adds a `grain/grain.js` module, which contains a type and
logic for representing Grain balances with 18 digits of precision. We
use the native BigInt type (and add the necessary babel plugin to
support it).

Unfortunately, Flow does not yet support BigInts (see
[facebook/flow#6639]). To hack around this, we lie to Flow, claiming
that BigInts are numbers, and we expect/suppress the flow errors
whenever we actually instantiate one. For example:

```js
// $ExpectFlowError
const myBigInt = 5n;
```

We can use the BigInt operators like `+`, `-`, `>` without flow errors,
since these actually exist on numbers too. However, flow will fail to
detect improper combinations of regular numbers and BigInts:

```js
// $ExpectFlowError
const x = 5n;
const y = x + 5;
// Uncaught TypeError: Cannot mix BigInt and other types
```

Since any improper mixing will result in a runtime error, these issues
will be easy to detect via unit tests.

In addition to adding the basic Grain type, I exported a `format`
function which will display Grain balances in a human readable way.
It supports arbitrary decimal precision, groups large amounts with comma
separators, handles negative numbers, and adds a suffix string.

The format method is thoroughly documented and tested. Thanks to @Beanow
for valuable feedback on its implementation.

Test plan: See included unit tests. `yarn test` passes.

[facebook/flow#6639]: facebook/flow#6639
teamdandelion added a commit to sourcecred/sourcecred that referenced this issue Mar 14, 2020
This commit adds a `grain/grain.js` module, which contains a type and
logic for representing Grain balances with 18 digits of precision. We
use the native BigInt type (and add the necessary babel plugin to
support it).

Unfortunately, Flow does not yet support BigInts (see
[facebook/flow#6639]). To hack around this, we lie to Flow, claiming
that BigInts are numbers, and we expect/suppress the flow errors
whenever we actually instantiate one. For example:

```js
// $ExpectFlowError
const myBigInt = 5n;
```

We can use the BigInt operators like `+`, `-`, `>` without flow errors,
since these actually exist on numbers too. However, flow will fail to
detect improper combinations of regular numbers and BigInts:

```js
// $ExpectFlowError
const x = 5n;
const y = x + 5;
// Uncaught TypeError: Cannot mix BigInt and other types
```

Since any improper mixing will result in a runtime error, these issues
will be easy to detect via unit tests.

In addition to adding the basic Grain type, I exported a `format`
function which will display Grain balances in a human readable way.
It supports arbitrary decimal precision, groups large amounts with comma
separators, handles negative numbers, and adds a suffix string.

The format method is thoroughly documented and tested. Thanks to @Beanow
for valuable feedback on its implementation.

Test plan: See included unit tests. `yarn test` passes.

[facebook/flow#6639]: facebook/flow#6639
teamdandelion added a commit to sourcecred/sourcecred that referenced this issue Mar 14, 2020
This commit adds a `grain/grain.js` module, which contains a type and
logic for representing Grain balances with 18 digits of precision. We
use the native BigInt type (and add the necessary babel plugin to
support it).

Unfortunately, Flow does not yet support BigInts (see
[facebook/flow#6639]). To hack around this, we lie to Flow, claiming
that BigInts are numbers, and we expect/suppress the flow errors
whenever we actually instantiate one. For example:

```js
// $ExpectFlowError
const myBigInt = 5n;
```

We can use the BigInt operators like `+`, `-`, `>` without flow errors,
since these actually exist on numbers too. However, flow will fail to
detect improper combinations of regular numbers and BigInts:

```js
// $ExpectFlowError
const x = 5n;
const y = x + 5;
// Uncaught TypeError: Cannot mix BigInt and other types
```

Since any improper mixing will result in a runtime error, these issues
will be easy to detect via unit tests.

In addition to adding the basic Grain type, I exported a `format`
function which will display Grain balances in a human readable way.
It supports arbitrary decimal precision, groups large amounts with comma
separators, handles negative numbers, and adds a suffix string.

The format method is thoroughly documented and tested. Thanks to @Beanow
for valuable feedback on its implementation.

Test plan: See included unit tests. `yarn test` passes.

[facebook/flow#6639]: facebook/flow#6639
teamdandelion added a commit to sourcecred/sourcecred that referenced this issue Mar 14, 2020
This commit adds a `grain/grain.js` module, which contains a type and
logic for representing Grain balances with 18 digits of precision. We
use the native BigInt type (and add the necessary babel plugin to
support it).

Unfortunately, Flow does not yet support BigInts (see
[facebook/flow#6639]). To hack around this, we lie to Flow, claiming
that BigInts are numbers, and we expect/suppress the flow errors
whenever we actually instantiate one. For example:

```js
// $ExpectFlowError
const myBigInt = 5n;
```

We can use the BigInt operators like `+`, `-`, `>` without flow errors,
since these actually exist on numbers too. However, flow will fail to
detect improper combinations of regular numbers and BigInts:

```js
// $ExpectFlowError
const x = 5n;
const y = x + 5;
// Uncaught TypeError: Cannot mix BigInt and other types
```

Since any improper mixing will result in a runtime error, these issues
will be easy to detect via unit tests.

In addition to adding the basic Grain type, I exported a `format`
function which will display Grain balances in a human readable way.
It supports arbitrary decimal precision, groups large amounts with comma
separators, handles negative numbers, and adds a suffix string.

The format method is thoroughly documented and tested. Thanks to @Beanow
for valuable feedback on its implementation.

Test plan: See included unit tests. `yarn test` passes.

[facebook/flow#6639]: facebook/flow#6639
@seanlangbrown
Copy link

BigInt support would really help with a project I'm working on.
I see there are 2 PRs for BigInts that have been open for 1 year.
Are these just waiting for review or is there anything someone (like me :) ) can contribute to help resolve this issue?

@nnmrts
Copy link
Contributor

nnmrts commented May 30, 2020

Can we first have support for Array please?

@Brianzchen
Copy link
Contributor

I'm still getting the error BigInt bigint [1] is not yet supported. [bigint-unsupported] in latest version.

cc @mroch any insight? 🙏

@gkz
Copy link
Member

gkz commented Dec 6, 2022

BigInt is now supported as of 0.194

@gkz gkz closed this as completed Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants