Is it possible to create an object/class/interface that represents a Function signature?

Asked

Viewed 413 times

3

Everything already works as expected in my code. What I want is to make it more verbose, making the signatures of the method more self-explanatory (I know I can use Docs comments for this, but I would also like to use the types of Typescript) and can be better validated by Tslint's of life.

What I have today:

class Test{
    testMetadada<T>(expression: (t: T) => void) {
        // ...
    }
}

The object expression is the type (t: T) => void, which is not very explanatory, I would like for example that something like:

class Expression<T> extends (t: T) => void{

}

or

interface Expression<T> extends (t: T) => void{

}

or

let Expression = ((t: T) => void)<T>;

So my method would be something like:

class Test{
    testMetadada<T>(expression: Expression) {
        // ...
    }
}

Where Expression represented the same (t: T) => void.

Is there anything I can do about it?

Behold here’s the example of what I’m trying to implement with this (the possibility of using Arrow function of Typescript as expressions Lambda Expressions of C# to obtain metadata)

  • I liked the question. I think I can think of something if you give a more "palpable" example, I couldn’t quite understand what you want to do.

  • @LINQ, well, what I want is nothing functional, is just to be able to create a Type, which presents the Function parameter. Looking at it now it seems to be something a little confusing indeed. I don’t quite know how to have something more "palpable". Looked at the example? What is not clear to you? If you can ask me about the points you don’t understand about my goal?

  • @LINQ, see, what I want is to make the guy (t: T) => void of the method parameter testMetadada a guy really in the Typescript, this could be through an Object, Class or Interface. Will improved?

1 answer

2


Browser other questions tagged

You are not signed in. Login or sign up in order to post.