You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* `implements` checks that a class's instance shape matches the type
1464
+
* `extends` requires a real base class value at runtime
1465
+
1466
+
```ts
1467
+
interfaceShape {
1468
+
area():number;
1469
+
}
1470
+
1471
+
declareclassBaseShape {
1472
+
area():number;
1473
+
}
1474
+
1475
+
classAimplementsShape {
1476
+
area() { return0; }
1477
+
}
1478
+
1479
+
classBextendsBaseShape {
1480
+
}
1481
+
```
1482
+
1483
+
In the example above, `A` is only checked structurally. `B` inherits from `BaseShape`, so `BaseShape` must exist at runtime.
1484
+
1485
+
Common symptoms of confusion:
1486
+
1487
+
* Using `declareclass` where only an object shape exists: `extends` compiles, but the emitted inheritance code fails at runtime
1488
+
* Using `interface` where an existing class should have been described: `implements` works, but there is no inherited behavior, and runtime checks like `instanceof` do not apply
1489
+
1490
+
Rule of thumb:
1456
1491
1457
-
Seehttp://stackoverflow.com/a/14348084/1704166
1492
+
* Use `interface` for "objects with these members"
1493
+
* Use `declareclass` for "this constructor exists at runtime"
1458
1494
1495
+
See also [this StackOverflow answer](http://stackoverflow.com/a/14348084/1704166).
1459
1496
1460
1497
### What does it mean for an interface to extend a class?
0 commit comments