#Resolver decorator and method return type safety?

10 messages · Page 1 of 1 (latest)

foggy finch
#

In the example I am returning a String type from the decorator and an array of countries from the method.

timber sky
#

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.

toxic sky
#

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.

timber sky
#

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

toxic sky
#

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 😦

timber sky
#

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

timber sky
#

Dang that's impressive!