From a1b2eb7aba6cdd44b8b8d3da4d2efa163c00eea1 Mon Sep 17 00:00:00 2001 From: Nelson Martell Date: Thu, 3 Nov 2022 11:05:16 -0500 Subject: [PATCH] docs: add Typescript example for .terminalWidth() (#2224) Add example note of `.wrap()` method usage with `.terminalWidth()`. Ref: https://github.com/yargs/yargs/pull/165#issuecomment-1214959504 Co-authored-by: Benjamin E. Coe --- docs/typescript.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/typescript.md b/docs/typescript.md index 9f69abac1..2086c45e7 100644 --- a/docs/typescript.md +++ b/docs/typescript.md @@ -121,6 +121,23 @@ interface Arguments { } ``` +If you need to use [`.wrap()`](https://yargs.js.org/docs/#api-reference-wrapcolumns) with `.terminalWidth()`, you may need to create instance first: + +```ts +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; + +// ... + +const yargsInstance = yargs(hideBin(process.argv)); + +cosnt args = yargsInstance + .wrap(myYargs.terminalWidth()) + // .otherMethods(...) + .argv + +``` + # More specific typing for choices() To improve the `choices` option typing you can also specify it as const: