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

Support non-promise function options in TypeScript #313

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jacobpgn
Copy link

Summary

Hey folks, thanks for the library! This is a small change to the types, with no functional changes, which should hopefully make things a tiny bit cleaner for users.


These functions don't really need to be async but currently the types require that they are. For example, currently this is an invalid option:

onSignal: () => logger.info("signal received")

and instead you'd have to write:

onSignal: async () => logger.info("signal received")

which might trigger a linter error such as typescript-eslint's Async method 'onSignal' has no 'await' expression.

or

onSignal: () => {
  logger.info("signal received")
  return Promise.resolve()
}

which creates a promise for no reason other than to satisfy the types!

With this PR the types make it clear that you can actually just return nothing or, in the case of the health checks, return a value without using async/await or creating a promise.

Changelog

Update types to support non-promise function options

These functions don't really _need_ to be async but currently the types
require that they are. For example, currently this is an invalid option:

```typescript
onSignal: () => logger.info("signal received")
```

and instead you'd have to write:

```typescript
onSignal: async () => logger.info("signal received")
```

which might trigger a linter error such as typescript-eslint's
`Async method 'onSignal' has no 'await' expression.`

or

```typescript
onSignal: () => {
  logger.info("signal received")
  return Promise.resolve()
}
```

which creates a promise for no reason other than to satisfy the types!

With this PR the types make it clear that you can actually just return
nothing or, in the case of the health checks, return a value without
using async/await or creating a promise.
@jacobpgn jacobpgn requested a review from a team as a code owner March 12, 2024 23:56
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

Successfully merging this pull request may close these issues.

1 participant