sindresorhus / meow

🐈 CLI app helper
MIT License
3.53k stars 150 forks source link

Set showHelp return type to never #213

Closed ryanrhee closed 2 years ago

ryanrhee commented 2 years ago

Since showHelp() calls into process.exit(), they should use the same return type.

The return type of process.exit() is never, not void. This tells the typescript compiler that code branches that have showHelp() terminate, and that any code written as executing after showHelp() should be considered dead code (similar to code after a return statement).

ryanrhee commented 2 years ago

As a workaround:

  const foo: string | undefined = "foo"

  function showHelp(): never {
    cli.showHelp()
    throw new Error("This is unreachable code")
  }

  if (foo === undefined) {
    showHelp()
  }

  // type of foo is now `string`