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

Refactor isPromise function #222

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

Conversation

tanvirstreame
Copy link

@tanvirstreame tanvirstreame commented Mar 19, 2024

Refactor for clean code

@@ -1,3 +1,3 @@
export function isPromise(value: any): value is Promise<any> {
return value && value.then !== undefined ? true : false
return value instanceof Promise;
Copy link
Owner

Choose a reason for hiding this comment

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

what about PromiseLike entities?

Copy link
Author

Choose a reason for hiding this comment

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

Good point. I want to make this line more understandable. How about I change this to -

export function isPromise(value: any): value is Promise<any> {
  return value?.then instanceof Function;
}

Copy link
Author

Choose a reason for hiding this comment

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

or this -

export function isPromise(value: any): value is Promise<any> {
  return Boolean(value && value.then);
}

@tanvirstreame tanvirstreame force-pushed the refactor branch 3 times, most recently from 30aa0f7 to 05cb555 Compare March 19, 2024 13:28
@tanvirstreame tanvirstreame changed the title Refactor isPromise function with instanceof Promise Refactor isPromise function Mar 19, 2024
@tanvirstreame tanvirstreame changed the title Refactor isPromise function Refactor isPromise function Mar 19, 2024
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