cac icon indicating copy to clipboard operation
cac copied to clipboard

Number out of precision.

Open tvrcgo opened this issue 6 years ago • 5 comments

I passed a number out of precision:

cli -n 1002822319600013312

got n = 1002822319600013300, a number

cli -n "1002822319600013312"

also got n = 1002822319600013300, a number

May be better to parse parameter as string first and auto convert to number if within precision. :)

tvrcgo avatar Jun 02 '18 08:06 tvrcgo

what if cli.option('n', { type: 'string', desc: 'something' }) ?

egoist avatar Jun 02 '18 10:06 egoist

I use cli.command to init command and type is not working.

like this:

node bin/cli.js destroy 1002822319600013312

destroy a record by id.

tvrcgo avatar Jun 02 '18 10:06 tvrcgo

I think it's a minimist issue, related to this line: https://github.com/substack/minimist/blob/4cf45a26b9af5f4ddab63107f4007485e576cfd3/index.js#L186

For a workaround, you can use process.argv[3] directly.

egoist avatar Jun 02 '18 12:06 egoist

Minimist is no longer a dependency it seems and the issue is still happening

tonyxiao avatar Jul 21 '21 05:07 tonyxiao

If you use something like:

cli
  .command("<...strings>", "strings")
cli.ts 123 123 123

You'll get ["123","123","123"]

But if you add

cli
  .command("<...strings>", "strings")
  .option("-j, --json", "Output as JSON")
cli.ts --json 123 123 123

It sets strings to:

[123, "123", "123"]

This whole auto-conversion by guessing needs to go. Args are strings unless explicitly declared otherwise.

minimist has the same issue and it's so annoying. I believe deno flags too.

In this specific example there is no big problem since I could convert it back. The real problem is when args are long strings like package numbers that look like numbers, but as soon as you auto convert them the data is lost because JS can't handle so big "numbers".

MaikuMori avatar Jan 05 '23 15:01 MaikuMori