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

Usage command builder function incorrectly documented #2321

Closed
H0R5E opened this issue Apr 23, 2023 · 3 comments · Fixed by #2328
Closed

Usage command builder function incorrectly documented #2321

H0R5E opened this issue Apr 23, 2023 · 3 comments · Fixed by #2328
Labels

Comments

@H0R5E
Copy link

H0R5E commented Apr 23, 2023

Hi, I am trying to use the usage command as a default alias as described in the docs here, using typescript as follows:

#!/usr/bin/env node

import yargs from 'yargs/yargs';

const argv = yargs(process.argv.slice(2))
  .usage('$0 <port>', 'start the application server', (yargs) => {
    yargs.positional('port', {
      describe: 'the port that your application should bind to',
      type: 'number'
    })
  }).parseSync()

console.log(argv)

However, when I go to compile this, I get the following error:

blah - error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'boolean'.

6   .usage('$0 <port>', 'start the application server', (yargs) => {
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/@types/yargs/index.d.ts:637:9
    637         usage<O extends { [key: string]: Options }>(
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    638             command: string | ReadonlyArray<string>,
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ...
    641             handler?: (args: ArgumentsCamelCase<InferredOptionTypes<O>>) => void | Promise<void>,
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    642         ): Argv<T>;
        ~~~~~~~~~~~~~~~~~~~
    The last overload is declared here.

EDIT: the yargs version is 17.7.1

Any help is greatly appreciated.

Best wishes,

Mat

@shadowspawn
Copy link
Member

Thanks for the complete example application. The TypeScript definition expects the builder function to return the freshly configured yargs instance. Here, I have just added a return in your builder function.

const argv = yargs(process.argv.slice(2))
  .usage('$0 <port>', 'start the application server', (yargs) => {
    return yargs.positional('port', {
      describe: 'the port that your application should bind to',
      type: 'number'
    })
  }).parseSync()

@shadowspawn
Copy link
Member

(I think the example in the documentation for usage is missing the return.)

@H0R5E
Copy link
Author

H0R5E commented Apr 24, 2023

Here, I have just added a return in your builder function.

Thanks, works for me!

@H0R5E H0R5E changed the title Usage command overload not recognized in typescript Usage command builder function incorrectly documented Apr 24, 2023
@bcoe bcoe closed this as completed in #2328 May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants