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

grpc-js: stricter function check than instanceof #1761

Merged
merged 3 commits into from Apr 27, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/grpc-js/src/client.ts
Expand Up @@ -198,9 +198,9 @@ export class Client {
options: CallOptions;
callback: UnaryCallback<ResponseType>;
} {
if (arg1 instanceof Function) {
if (Object.prototype.toString.call(arg1) === '[object Function]') {
Copy link
Member

Choose a reason for hiding this comment

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

Can you extract this condition into an isFunction function?

Copy link
Contributor Author

@zereraz zereraz Apr 24, 2021

Choose a reason for hiding this comment

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

have updated in the latest commit

return { metadata: new Metadata(), options: {}, callback: arg1 };
} else if (arg2 instanceof Function) {
} else if (Object.prototype.toString.call(arg2) === '[object Function]') {
if (arg1 instanceof Metadata) {
return { metadata: arg1, options: {}, callback: arg2 };
} else {
Expand All @@ -211,7 +211,7 @@ export class Client {
!(
arg1 instanceof Metadata &&
arg2 instanceof Object &&
arg3 instanceof Function
Object.prototype.toString.call(arg3) === '[object Function]'
)
) {
throw new Error('Incorrect arguments passed');
Expand Down