#Resolver decorator and method return type safety?
10 messages · Page 1 of 1 (latest)
Decorators cannot effect the Typescript type, limitation of the language, so you'd be stuck with trying to find some mixin approach or an eslint rule that restricts this.
It is possible to enforce that a decorator match a function return type via some typescript magic. I was able to implement type-safe MessagePattern decorators that way, but that was for a pre-defined set of interfaces. I'm not sure if it's possible to do it here.
Right, I was able to make a @Command() that only worked in classes that extended CommandRunner, but for wondering like this I don't think there's a way to say that the types have to match
I mean I created a decorator that could be only used on a method that returned a specific type. Now I'm intrigued enough to try this in the typescript playground 😆
Btw I had the opportunity to work on a python project the other day and python decorators can alter the signature of a method. Something that's been requested so long by the typescript community 😦
Gotta love language limitations. I'm honestly hoping when the new decorators start supporting type metadata this will be available. But who knows when they'll get to that
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
I was able to create a TypedQuery wrapper which can only be applied over methods that return the type or an array of types
Dang that's impressive!