cmd-ts icon indicating copy to clipboard operation
cmd-ts copied to clipboard

Contravariance for oneOf and defaultValue

Open mizchi opened this issue 3 years ago • 0 comments

Example

import * as cmd from "cmd-ts";
cmd.command({
  name: 'regression',
  args: {
    target: cmd.option({
      type: cmd.oneOf(['stable', 'canary']),
      long: 'target',
      defaultValue() {
        return 'stable'; // Error
      }
    }),
});

TS Result: Type '() => string' is not assignable to type '() => "stable" | "canary"'.

Expected

No Error.

Accept return value: 'stable' as 'stable' | 'carary'

mizchi avatar Jul 22 '22 08:07 mizchi