You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let args = yargs()
.command('example', '...', {
test:{
choices: ["a", "b"] as const;
}
})
.parseSync()
//<------- error: Argument of type 'unknown' is not assignable to parameter of type '"a" | "b"'.ts(2345)
test(args._[0].test)
function test(value: 'a' | 'b'){}
The text was updated successfully, but these errors were encountered:
% node ts.js example --test ts.js example...Options: --help Show help [boolean] --version Show version number [boolean] --test [choices: "a", "b"]Invalid values: Argument: test, Given: true, Choices: "a", "b"
this is not the issue, yargs itself can detect the user's input.
but the issue is that there is no way to tell typescript the correct type, you need to always cast each arg before using it
To reproduce the issue:
1- starting from your snippet, add a single line argv.test
2- hover over argv.test to see its type. it should be something like a | b, but instead it is just unknown
The text was updated successfully, but these errors were encountered: