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

Update app.ts #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions step19a_classes/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ TypeScript is a superset of JavaScript and JavaScript does not, of course, have
compatibility). TypeScript has to figure out assignability on its own.

To determine if two classes are assignable, TypeScript uses what it calls "structural subtyping." With structural subtyping,
TypeScript compares the properties and methods on the two objects. If the variable on the left-hand side of the equals sign has all the
properties and the methods of the object on the right-hand side of the equals sign, then the two objects are assignable.
TypeScript compares the properties and methods on the two objects. If the variable on the left-hand side of the equals sign has all or some of the
properties and the methods of the object on the right-hand side of the equals sign and has no extra properties than the object on the right-hand side,
then the two objects are assignable.
This is a form of "duck typing" (from the old saying: "If it looks like a duck, walks like a duck and quacks like a duck, then it's a duck").

With structural subtyping, it's perfectly OK for the object on the left-hand side to have more properties than the object on the right,
With structural subtyping, it's perfectly OK for the object on the right-hand side to have more properties than the object on the left,
it just can't have fewer properties. Obviously, any class that derives from another class will have all of the properties of the base interface.

Structural subtyping lets TypeScript support extending classes defined in other libraries.
Expand Down