Skip to content

Commit 7a8cd5a

Browse files
committed
grpc-js: Use helper isFunction
1 parent 076aecc commit 7a8cd5a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/grpc-js/src/client.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ const INTERCEPTOR_SYMBOL = Symbol();
5555
const INTERCEPTOR_PROVIDER_SYMBOL = Symbol();
5656
const CALL_INVOCATION_TRANSFORMER_SYMBOL = Symbol();
5757

58+
function isFunction<ResponseType>(arg: Metadata | CallOptions | UnaryCallback<ResponseType>): boolean {
59+
return Object.prototype.toString.call(arg) === '[object Function]'
60+
}
61+
5862
export interface UnaryCallback<ResponseType> {
5963
(err: ServiceError | null, value?: ResponseType): void;
6064
}
@@ -198,9 +202,9 @@ export class Client {
198202
options: CallOptions;
199203
callback: UnaryCallback<ResponseType>;
200204
} {
201-
if (Object.prototype.toString.call(arg1) === '[object Function]') {
205+
if (isFunction(arg1)) {
202206
return { metadata: new Metadata(), options: {}, callback: arg1 };
203-
} else if (Object.prototype.toString.call(arg2) === '[object Function]') {
207+
} else if (isFunction(arg2)) {
204208
if (arg1 instanceof Metadata) {
205209
return { metadata: arg1, options: {}, callback: arg2 };
206210
} else {
@@ -211,7 +215,7 @@ export class Client {
211215
!(
212216
arg1 instanceof Metadata &&
213217
arg2 instanceof Object &&
214-
Object.prototype.toString.call(arg3) === '[object Function]'
218+
isFunction(arg3)
215219
)
216220
) {
217221
throw new Error('Incorrect arguments passed');
@@ -671,3 +675,4 @@ export class Client {
671675
return stream;
672676
}
673677
}
678+

0 commit comments

Comments
 (0)