Skip to content

Conversation

novemberborn
Copy link
Member

  • Explicitly type t.teardown() functions to return a promise
  • Fix typing of plugin teardown. The returned method always returns Promise.

The teardown functions may or may not return a promise. Support both to help with the @typescript-eslint/no-misused-promises ESLint rule.

This helps with the @typescript-eslint/no-misused-promises ESLint rule.
The returned method always returns Promise<void>. The teardown function itself may or may not return a promise. Support both to help with the @typescript-eslint/no-misused-promises ESLint rule.
publish: (data: Data) => PublishedMessage<Data>;
subscribe: () => AsyncIterableIterator<ReceivedMessage<Data>>;
teardown: <TeardownFn extends () => void> (fn: TeardownFn) => TeardownFn;
teardown: (fn: (() => Promise<void>) | (() => void)) => () => Promise<void>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
teardown: (fn: (() => Promise<void>) | (() => void)) => () => Promise<void>;
teardown: (fn: (() => Promise<void> | void) => () => Promise<void>;

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that be fine or would void "nullify" Promise<void>? Or would it be clearer to have overloads?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm: microsoft/TypeScript#43921

I guess what you have is fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know if overloads will make any difference.

@novemberborn novemberborn merged commit 388ea53 into main Apr 10, 2022
@novemberborn novemberborn deleted the teardowns-may-return-promise branch April 10, 2022 16:30
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.

2 participants