Alternate syntax for function overloads #30453
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
class method signature
method signature
function overload syntax
function overload
proxy function
proxy function signature
Suggestion
A new syntax for function overloads:
This would allow types to be less static, and often more accurate to the purpose of the overloaded function
Right now, we can do something similar using
const
-however, the differences in detailed in #25761 and the lack of any equivalent in classes make this a separate issue.
I'm not dead set on the
as
syntax, but I think it fits with what we already have quite well. The checking done on overloads is similar to that of({ prop: "HI" } as { prop: number })
, and it fits well in and out of classesIt's also worth noting that every use case of this would benefit greatly from #28172
Use Cases
Generic Types
Inheritance
Combining function implementations
A solution to the problems brought up in #12041 -
Which would work particularly well combined with #28172,
fully checking the types against the current signature of both implementations, and emitting useful errors
Examples
This came up in the context of an argument parser, where I attempt to parse the values using a direct proxy to another method -
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: