Skip to content
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

Do we need to explicitly annotate classes implementing interfaces? #5

Open
samuelgoto opened this issue Jul 11, 2017 · 0 comments
Open

Comments

@samuelgoto
Copy link
Owner

samuelgoto commented Jul 11, 2017

(porting comments from @domenic to github issues)

@domenic: challenges with introducing new interface syntax and concepts (especially classes implementing interfaces).

// Examples
interface Bar {
  hello(a: number): number;
}
 
class Foo implements Bar {
  bar(a: number) : number {
    return 0;
  }
}

@domenic: Is this (class Foo implements Bar) really necessary? Why? The type checker can tell what interfaces a class implements without any manual annotation.

@goto: Hum, that's a good point, interfaces being structurally typed. @dimvar help me out here?

@dimvar: It's like TypeScript. If you define explicitly that a class implements an interface, then the type checker checks that it does. If you don't, then you can pass class instances to places that expect the interface, and you would get warnings there. Another benefit of letting a class specify the interfaces it implements is that it's good for documentation.

@domenic: That's a pretty dubious value proposition, IMO, for using up such valuable syntactic space and a keyword. (For example, people have proposed using implements in this position for runtime mixins.)

@dimvar: Letting a class specify that it implements an interface has a few advantages: 1) An author of the library/module can say that class A implements B, and have that checked, even if there is no place in the library where an instance of A is passed to a context that expects a B. 2) When A explicitly says that it implements B, then checking that A is a subtype of B is quick, it's a tag check, otherwise, we have to structurally check it, which involves looking at all properties of B. If the specific word implements is too valuable, we could find some other keyword, or new syntax to express this.

@domenic: Yes, I understood the advantages, I just think they are really marginal for the weight they add to a supposed MVP. (Especially one based on speed in a system which is known to make things slower.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant