-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
feature(microservices): Return correct client type in ClientProxyFactory #2240
feature(microservices): Return correct client type in ClientProxyFactory #2240
Conversation
public static create( | ||
clientOptions: { transport: Transport.MQTT } & ClientOptions, | ||
): ClientMqtt; | ||
public static create(clientOptions: ClientOptions): ClientProxy & Closeable; |
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.
This line has to be "duplicated" so a parameter of type ClientOptions
is still valid (used in microservices/module/ClientsModule
)
63382ed
to
7e4f4e4
Compare
Pull Request Test Coverage Report for Build 2930
💛 - Coveralls |
So actually the main idea behind However, Could you change this PR so this method still returns |
Add overload to the ClientProxyFactory for better type security. This allows the user to not cast the GRPC client to any after creating it using the factory.
7e4f4e4
to
17cb7ff
Compare
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
At the moment
ClientProxyFactory.create
will always return the typeClientProxy & Closeable
. Therefore it will not take the giventransport
option into consideration, even though we would know what type should be returned.On top of that
ClientProxy & Closeable
is straight up wrong with some clients, such as theGrpcClient
.Calling
.connect()
fromClientProxy & Closeable
onClientGrpc
would result in this error:Error: The "connect()" method is not supported in gRPC mode.
What is the new behavior?
Adds overloads to the
ClientProxyFactory
for better type security.This allows the user to not cast the client to any after creating it
using the factory.
Does this PR introduce a breaking change?
Other information
The
ClientProxyFactory
is used in@nestjs/terminus
to dynamically create a microservice client on the fly. Better type security would lead to a better code :)