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 server-related types exported by grpc-js #972
Improve server-related types exported by grpc-js #972
Conversation
packages/grpc-js/src/server-call.ts
Outdated
@@ -18,13 +18,14 @@ | |||
import { EventEmitter } from 'events'; | |||
import * as http2 from 'http2'; | |||
import { Duplex, Readable, Writable } from 'stream'; | |||
import * as util from 'util'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
util.isNumber()
and util.isString()
are deprecated in favor of typeof value === 'number'
and typeof value === 'string'
, respectively.
packages/grpc-js/src/server-call.ts
Outdated
? error.metadata | ||
: new Metadata(), | ||
}; | ||
|
||
if (error.hasOwnProperty('code') && Number.isInteger(error.code)) { | ||
if ('code' in error && util.isNumber(error.code) && Number.isInteger(error.code)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The util.isNumber()
(or typeof error.code === 'number')
check shouldn't be necessary due to the Number.isInteger()
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Typescript was not happy with calling Number.isInteger
on that value without verifying that it was a number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right: microsoft/TypeScript#21199 😕
This mainly makes the server call types and
Server#registerService
function signature more specific, the server error types more permissive, and exports some more types needed for writing service implementations.Also, this fixes a typo in the native library's
index.d.ts
that got brought up in #965. That class is essentially internal, so code written using the typo works. I have added an alias to avoid breaking that.