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
Copy file name to clipboardExpand all lines: pages/Advanced Types.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -813,7 +813,7 @@ let carProps: keyof Car; // the union of ('manufacturer' | 'model' | 'year')
813
813
```
814
814
815
815
`keyof Car` is completely interchangeable with `'manufacturer' | 'model' | 'year'`.
816
-
The difference is that if you add another property to `Car`, say `ownersAddress: string`, then `keyof Person` will automatically update to be `'manufacturer' | 'model' | 'year' | 'ownersAddress'`.
816
+
The difference is that if you add another property to `Car`, say `ownersAddress: string`, then `keyof Car` will automatically update to be `'manufacturer' | 'model' | 'year' | 'ownersAddress'`.
817
817
And you can use `keyof` in generic contexts like `pluck`, where you can't possibly know the property names ahead of time.
818
818
That means the compiler will check that you pass the right set of property names to `pluck`:
To satisfy this requirement, we create stand-in properties and their types for the members that will come from our mixins.
117
-
This satisfies the compiler that these members will be available at runtime.
118
-
This lets us still get the benefit of the mixins, albeit with some bookkeeping overhead.
109
+
The first thing you may notice in the above is that instead of trying to extend `Disposable` and `Activatable` in `SmartObject` class, we extend them in `SmartObject` interface. `SmartObject` interface will be mixed into the `SmartObject` class due to the [declaration merging](./Declaration%20Merging.md).
119
110
120
-
```ts
121
-
// Disposable
122
-
isDisposed:boolean=false;
123
-
dispose: () =>void;
124
-
// Activatable
125
-
isActive:boolean=false;
126
-
activate: () =>void;
127
-
deactivate: () =>void;
128
-
```
111
+
This treats the classes as interfaces, and only mixes the types behind Disposable and Activatable into the SmartObject type rather than the implementation. This means that we'll have to provide the implementation in class.
112
+
Except, that's exactly what we want to avoid by using mixins.
129
113
130
-
Finally, we mix our mixins into the class, creating the full implementation.
114
+
Finally, we mix our mixins into the class implementation.
0 commit comments