Skip to content
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

Make gracefulExit return never instead of void #38

Open
jgoux opened this issue Mar 27, 2024 · 3 comments
Open

Make gracefulExit return never instead of void #38

jgoux opened this issue Mar 27, 2024 · 3 comments

Comments

@jgoux
Copy link

jgoux commented Mar 27, 2024

Hello 👋,

Shouldn't gracefulExit reflect the return type of process.exit? (defined here).

With this change, it will correctly tell TypeScript that everything called after gracefulExit won't be executed and don't add the void type where it shouldn't be.

Here is a playground showing the issue: https://tsplay.dev/wgo5bw
The same playground using never: https://tsplay.dev/WY5jEW

As a workaround, I'm using module augmentation to redefine gracefulExit definition:

// global.d.ts

module "exit-hook" {
  export function gracefulExit(signal?: number): never;
}
@sindresorhus
Copy link
Owner

Unlike process.exit(), it does not exit synchronously.

@jgoux
Copy link
Author

jgoux commented Mar 29, 2024

Unlike process.exit(), it does not exit synchronously.

What is the expectation here? Do we expect people to execute code after gracefulExit is called?

@qraynaud
Copy link

qraynaud commented May 6, 2024

Unlike process.exit(), it does not exit synchronously.

What is the expectation here? Do we expect people to execute code after gracefulExit is called?

I think this is less about expectation and more about what’s effectively happening. Whether you want the code after to be executed or not, it will be. So you NEED to account for that. Making it look like it won’t be executed is a problem in and out of itself.

That’s why I suggested #35 instead. It would allow you to await gracefulExit(code) and it would effectively stop execution there (at least in this branch, it would not prevent other events to fire and the associated code to be executed) since the promise would never resolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants