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
docs: Fix example of coerce #2316
Conversation
Making the examples correct is a good thing. The example was updated as part of adding async support to Would you like to do that? |
I modified the example to add an |
I like the direction of getting away from It is much easier to run the example in a module where top-level await is available. How about about making this example esm? e.g. import { readFile } from 'node:fs/promises';
import yargs from 'yargs';
const argv = await yargs(process.argv.slice(2))
.coerce('file', async (arg) => readFile(arg, 'utf8'))
.parseAsync(); |
In your example, the I propose to add an intermediate variable (which is useless, but there is no ESLint rule to detect it) to have an excuse to use an import { readFile } from 'node:fs/promises';
import yargs from 'yargs';
const argv = await yargs(process.argv.slice(2))
.coerce('file', async (arg) => {
const content = await readFile(arg, 'utf8');
return content;
})
.parseAsync(); |
Good points. I suggest adding |
I added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for the PR and conversation @regseb. |
The first example of
.coerce(key, fn)
is invalid: anawait
is used in a non-async
function.