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

Improve typing of teardown methods #3003

Merged
merged 2 commits into from Apr 10, 2022
Merged

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.
@@ -41,7 +41,7 @@ export namespace SharedWorker {
readonly file: string;
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.

None yet

2 participants