Unclear how to set `ctx.res` in TypeScript implementation
See original GitHub issuehttps://github.com/malijs/mali/pull/53 added TypeScript type definitions, but I’m having trouble figuring out how to use the simple examples from the docs. Following the docs (https://mali.js.org/guide/context.html#context), in my handler I set ctx.res = { foo: 'bar' }
to set the response value, which leads to the TypeScript error Type '{ status: ServingStatus; }' is not assignable to type 'GrpcResponse'
.
It seems to me the union type of GrpcResponse
should include any
, because you’re supposed to be able to set the res property to the actual response message / object. https://mali.js.org/guide/context.html#ctx-res
In all other cases set the res property to the actual response message / object in case of UNIRY and REQUEST_STREAM calls, and to the output stream in case of RESPONSE_STREAM calls
Am I understanding this right? What is the proper way to set Context.res
in TypeScript?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Hi @bojand settings the types to
any
solves the issue currently but no the root issue.@sykorax wrote here the best solution - https://github.com/malijs/mali/issues/43#issuecomment-472823653
Ideally, I would like to write the next code:
if we can make this happen I will try to write typescript generator for protobuf that supports mali convention of
ctx
If you want I can submit a PR for this
This is still an issue in 0.19.0.
GrpcRequest
andGrpcResponse
are now set to beany
, resulting in having to do something like the following:It seems like
Context
should be generic and can fall back toany
if no params are given. This shouldn’t be too hard, if there’s no issues with it I’m happy to submit a PR?