Cast Method of a class to a certain type #39623
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Search Terms
casting
type
interface
method
function
parameters
inference
class
Suggestion
Currently, it is impossible to infer the parameters and the return types of a method of a class using a type
The goal is to be able to declare a method without repeating the param types and the return type. I used typescript
Type
for that.But there is currently no way to do this without changing the compiled javascript code.
I tried
BUT unfortunately, this changes the javascript code compiled into:
I am looking for something that compiles into:
Another option currently is to declare an interface and implement it on the class like so:
HOWEVER, this approach would bnd the method name to only
sum
. What if I want to use the same method type with a different name likedivide
ormultiply
Use Cases
It will be used like this
Examples
or
or
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: