0

When using the builder provided by yargs with chained calls like the following example, everything works fine.

const foo = yargs(stringArray)
    .string('bar')
    .describe({
        'bar': 'informative text',
    }).argv;

But when trying to achive the same code by splitting it and using the value of foo, it seems to break:

const foo = yargs(stringArray);
foo.string('bar')
    .describe({
        'bar': 'informative text',
    }).argv; //this does compile, but not work

Coming from a Java background I would assume that the first line returns a builder and it would not matter if I chain the function calls or call it on a variable containing the output of the first line. That seems not to be the case here. What am I missing? Has this something to do with the library (in this case it's yargs) or is this general behavior in typescript for this kind of pattern?

Nerethar
  • 1
  • 1
  • 1
  • Could you be more specific? What do you mean by "not work"? If you do something with `foo` like `console.log()` the second snippet does not change the initial object, so you need to assign a result of chain to some variable first. – Shlang Apr 06 '20 at 20:54

1 Answers1

0

The error was a simple mistake: In the second snippet, the return-value of the chain isn't saved anywhere, so obviously the object you want to retrieve won't be accessible.

Nerethar
  • 1
  • 1
  • 1