#yargs — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #yargs, aggregated by home.social.
-
Commander.jsの
.conflicts()や.implies()は、排他的な組み合わせをランタイムではちゃんと検出してくれます。でも
.opts()の型は賢くならず、戻り値は結局string | undefinedのままです。どのオプションが同時に使えないのかを、TypeScriptは知りません。このズレをパーサーコンビネータでどう型に落とし込めるか、Yargsとの比較も含めて書きました。後半では、環境変数・設定ファイル・対話プロンプトまで同じ型保証を広げる話もしています。
-
I wrote about a problem that's been bugging me with #Commander.js and #Yargs:
.conflicts()and.implies()enforce constraints at runtime, but the type you get back is still a flat object with every field optional. The compiler has no idea which options belong together.The post walks through what happens when you express the same constraints in the parser structure instead, and how #TypeScript turns that into a discriminated union where each branch carries only its own fields.
Second half covers a less obvious question: what happens when values come from env vars, config files, or prompts instead of argv, and whether the constraints should still hold across all of them.
https://hackers.pub/@hongminhee/2026/optique-10-discriminated-unions-for-cli