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

Use bool const type for rpc type #58

Merged
merged 1 commit into from
Jun 26, 2020
Merged

Conversation

smolijar
Copy link
Contributor

@smolijar smolijar commented Jun 7, 2020

Uses const types for requestStream and responseStream, either true
or false types instead of generic boolean TS types allowing advanced
call type inference from the service definition.

Higher abstraction framework libraries, such as
https://github.com/malijs/mali could leverage advanced type inference to
hint/check specific type handlers if this information would be part of
the type rpc service type definition.

At this point, the only way to determine thy type of RPC is using
I{{{serviceName}}}Server interface, which must be linked manually to
I{{{serviceName}}}Service methods. For registring handlers at runtime,
only e.g. GreeterService and corresponding implementation is required,
manually adding IGreeterServer is possible, but troublesome. This
would not be required if rpc type could be inferred using the const
booleans to define the type.

This change does is not a breaking change and the const boolean types
are working correctly since the oldest available version on TS
playground 2.4.1. See playground link in the trailers.

There are no obvoius disadvantages to using const booleans and change
could potentially give node grpc frameworks more power for sophisticated
type inference.

There are no tests in the project, but so at least I tried it manually
with npm link on a custom project and it behaves as expected.

See: https://www.typescriptlang.org/play/?ts=2.4.1#code/MYewdgzgLgBAhsYBTADlAKgJwK5JgXhgAoA3OAGwC4YockBKAgPhjPIChRJYFk0AxChDyFSFagDMhDZqwrt2vVBjpEp5YfUWJlgjUjXStStFlxFauYzoHSLdekA

Uses const types for `requestStream` and `responseStream`, either `true`
or `false` types instead of generic `boolean` TS types allowing advanced
call type inference from the service definition.

Higher abstraction framework libraries, such as
https://github.com/malijs/mali could leverage advanced type inference to
hint/check specific type handlers if this information would be part of
the type rpc service type definition.

At this point, the only way to determine thy type of RPC is using
`I{{{serviceName}}}Server` interface, which must be linked manually to
`I{{{serviceName}}}Service` methods. For registring handlers at runtime,
only e.g. `GreeterService` and corresponding implementation is required,
manually adding `IGreeterServer` is possible, but troublesome. This
would not be required if rpc type could be inferred using the const
booleans to define the type.

This change does is not a breaking change and the const boolean types
are working correctly since the oldest available version on TS
playground 2.4.1. See playground link in the trailers.

There are no obvoius disadvantages to using const booleans and change
could potentially give node grpc frameworks more power for sophisticated
type inference.

There are no tests in the project, but so at least I tried it manually
with `npm link` on a custom project and it behaves as expected.

See: https://www.typescriptlang.org/play/?ts=2.4.1#code/MYewdgzgLgBAhsYBTADlAKgJwK5JgXhgAoA3OAGwC4YockBKAgPhjPIChRJYFk0AxChDyFSFagDMhDZqwrt2vVBjpEp5YfUWJlgjUjXStStFlxFauYzoHSLdekA
@agreatfool
Copy link
Owner

Thanks for the pr. Let me have a look.

@agreatfool agreatfool merged commit 5cc6174 into agreatfool:master Jun 26, 2020
@agreatfool
Copy link
Owner

Sorry for the late reply. Version 4.1.0 has been published.

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