pkgjs / parseargs

Polyfill of `util.parseArgs()`
Apache License 2.0
121 stars 9 forks source link

Make `type` mandatory for configured options #94

Closed bakkot closed 2 years ago

bakkot commented 2 years ago

@bcoe suggested this here. I'm in favor of it, and wanted to open an issue for it so it doesn't get lost.

This would definitely apply to strict. I don't know if it should also apply to non-strict. I'm still not entirely clear on what non-strict is for, which makes it hard to judge what's right for it.

I note that if if type is not required for non-strict, you have odd cases like

parseArgs({ options: { foo: { multiple: true } }, args: ['--foo', 'a', '--foo'] })

where... would that give you { values: { foo: ['a', true] } }, or what?

shadowspawn commented 2 years ago

I don't know if it should also apply to non-strict.

I think it applies for both strict and non-strict.

shadowspawn commented 2 years ago

Per the original comment, the idea is to make the implicit configuration option illegal.

Implicit boolean type, no clues:

parseArgs({
  options: {
    foo: {},
  },
});

Explicit:

parseArgs({
  options: {
    foo: { type: 'boolean' },
  },
});