-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
very confused codes, which Point
is class & which Point
is Interface
#31788
Comments
Okay, an example for bad code. What is your point? Here is an example for how to use interfaces and classes together. You define an interface, then classes implement it. Don't override existing names, of course that will give you problems. Such usage questions are for StackOverflow. |
This does belong on Stack Overflow instead of here, but the code above doesn't have anything to do with a class implementing an existing interface, and therefore isn't necessarily "bad". Instead it shows declaration merging, which is useful when you want to add methods to existing classes whose source code you can't or don't want to modify. That's what the example code is doing... specifically it shows how a |
site: stackoverflow
https://jameshenry.blog/typescript-classes-vs-interfaces/ https://stackoverflow.com/questions/37233735/typescript-interfaces-vs-types |
Read about declaration merging: https://www.typescriptlang.org/docs/handbook/declaration-merging.html |
In short: Every class also carries with it an interface of the same name, in order to accurately describe its instances. Declaring |
very confused codes, which
Point
is class & whichPoint
is Interfaceno-implicit-any-for-this
http://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html#no-implicit-any-for-this
The text was updated successfully, but these errors were encountered: