Closed shaunek-hero closed 4 months ago
I'm guessing that this might be a limitation of how Typescript+Javascript work "TypeScript is JavaScript with syntax for types" (cit.), it is on top of javascript which is an untyped language.
With that said I think that what you want must be searched on the Typescript framework, and from what I know the TS doesn't have this kind of feature.
Yeah you might be right about that. I'm not entirely certain though - I've started using some new-ish libraries that do some insane Typscript kung fu. I know Typscript okay as an app developer, but the guys who developed stuff like Drizzle and ElysiaJS are next level, and after using their libs (and small amounts of peeking under the hood) I wonder if what I'm asking for is possible.
In any case no reason to keep this ticket open since frankly I'm not even actively using this library and the idea was just something I thought I would float. All the best to you.
I've used the .NET MediatR package and enjoyed it so I have stumbled upon your package while working on a TS project and I like what you have done, kuddos.
One thing I've admired about the .NET package was that when you call
var result = await mediatr.Send(myCommand)
the IDE (or compiler I guess?) is able to smartly know the proper return type. As in the handler method's return type is typically something likeTask<int>
and then magically thevar result
is inferred automatically as an int. This package's api surface is so very similar to the original .NET package, but I notice that with this package when we dovar result = await mediator.send(myCommand)
theresult
is anunknown
... I do understand that specifyingawait mediator.send<number>(myCommand);
is a work around and the IDE thinks result is now a number, but it sure would be amazing if the send method could somehow automatically infer the return type of the handler method.I'm guessing that this might be a limitation of how Typescript+Javascript work (???), since I've seen that the
@nestjs/cqrs
package has a similar limitation where it'sQueryBus/CommandBus.execute()
will return anany
.And to be clear, I'm not yet a user of this package, I have just created a very small demo with your package and still trying to decide if I want to use it. Still I'm interested in it. Maybe you have already determined this isn't a possibility.