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

Optional bigint support #527

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

tristanmenzel
Copy link

Revisiting PR401 to add bigint support.

Hopefully this PR addresses the outstanding comments on the original PR.

Copy link
Owner

@bcherny bcherny left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up! A few stylistic suggestions -- the rest looks good.

@@ -0,0 +1,3 @@
# Treat text as lf
Copy link
Owner

Choose a reason for hiding this comment

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

Please remove this file from the PR.

Copy link
Author

Choose a reason for hiding this comment

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

without it you're relying on windows contributors having git configured to commit LF instead of CRLF which doesn't seem ideal

@@ -45,7 +45,7 @@ export function parse(
return parseLiteral(schema, keyName)
}

const types = typesOfSchema(schema)
const types = typesOfSchema(schema, options)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
const types = typesOfSchema(schema, options)
const types = typesOfSchema(schema)

Copy link
Author

Choose a reason for hiding this comment

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

options needs to be passed in so that the matchers can read the enableBigInt option

src/types/JSONSchema.ts Outdated Show resolved Hide resolved
src/utils.ts Outdated Show resolved Hide resolved
test/e2e/bigint.1.ts Outdated Show resolved Hide resolved
test/e2e/bigint.2.ts Outdated Show resolved Hide resolved
src/cli.ts Outdated Show resolved Hide resolved
src/generator.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
KtorZ and others added 6 commits June 15, 2023 08:31
  - This change isn't changing any of the existing behavior by default.
  - When enabled however, it'll generate integers with no 'maximum' property as 'bigint'.

  Why?

  While JSON supports big integers in its specification, JavaScript does
  not by default. Thus, trying to deserialise a large integer into a
  JavaScript number is doomed to fail. Since relatively recently
  however, JavaScript (and therefore TypeScript), natively supports a
  'bigint' type for numbers (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt),
  and there exists fixed parsers that can parse numbers into bigint
  directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants