-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: new syntax for defining abstract methods #6833
Comments
That looks like an abstract property to me. Take a look at #4669 -- is that what you're looking for? |
Sorry, no, I was talking about declaring the type of an abstract method. If we consider
then I would argue that f has type t. So why can't we just write:
Pro:
Note that this only goes for abstract methods, because we don't need the parameter names in the function body. Anyhow, If I think a little bit further, I would like to write for non-abstract methods:
That would be charming, because:
Mentally, types are also at a distinct level of programming, so separating them from code would reasonable. Note that point 1 goes well with the paradigm that parameters are mandatory and types are optional. The vanished parameter name in the type is meaningless anyway as we declare a type and not a function. |
The syntax you are proposing here is already used for property declarations in typescript. properties are not the same as methods in a class, methods go on the prototype, properties go on the instance, i do not think there is much we can change here. today: class C {
a: T; // this is a property whose name is "a" and type is T, and not a method
} Consider using an interface instead: type t = (x: number) => void;
interface A {
f: t;
}
class Base implements A{
f(x: number) {
}
} |
Currently, we write
Wouldn't it be nicer to write:
That would syntactically go smoothly with type aliases:
which currently (1.7.5) is disallowed. (See #6832).
The text was updated successfully, but these errors were encountered: