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
change the property and interface definition naming of 'backround' to 'background'.
The words 'backround' and 'background' are used in the same context. I don't know if it is a typo or not, but it would make sense to use 'background'.
type CoursePart = CoursePartBasic | CoursePartGroup |CoursePartBackround;
461
+
type CoursePart = CoursePartBasic | CoursePartGroup |CoursePartBackground;
462
462
```
463
463
464
464
### More type narrowing
@@ -483,7 +483,7 @@ One handy way to narrow these kinds of types in TypeScript is to use *switch cas
483
483
484
484

485
485
486
-
In the above example, TypeScript knows that a *part* has the type *CoursePart* and it can then infer that *part* is of either type *CoursePartBasic*, *CoursePartGroup* or *CoursePartBackround* based on the value of the attribute *kind*.
486
+
In the above example, TypeScript knows that a *part* has the type *CoursePart* and it can then infer that *part* is of either type *CoursePartBasic*, *CoursePartGroup* or *CoursePartBackground* based on the value of the attribute *kind*.
487
487
488
488
The specific technique of type narrowing where a union type is narrowed based on literal attribute value is called [discriminated union](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions).
489
489
@@ -492,10 +492,10 @@ Note that the narrowing can naturally be also done with *if* clause. We could eg
492
492
```js
493
493
courseParts.forEach(part=> {
494
494
if (part.kind==='background') {
495
-
console.log('see the following:', part.backroundMaterial)
495
+
console.log('see the following:', part.backgroundMaterial)
496
496
}
497
497
498
-
// can not refer to part.backroundMaterial here!
498
+
// can not refer to part.backgroundMaterial here!
499
499
});
500
500
```
501
501
@@ -523,14 +523,14 @@ default:
523
523
returnassertNever(part);
524
524
```
525
525
526
-
and remove the case that handles the type *CoursePartBackround*, we would see the following error:
526
+
and remove the case that handles the type *CoursePartBackground*, we would see the following error:
527
527
528
528

529
529
530
530
The error message says that
531
531
532
532
```text
533
-
'CoursePartBackround' is not assignable to parameter of type 'never'.
533
+
'CoursePartBackground' is not assignable to parameter of type 'never'.
534
534
```
535
535
536
536
which tells us that we are using a variable somewhere where it should never be used. This tells us that something needs to be fixed.
Now we know that both interfaces *CoursePartBasic* and *CoursePartBackround* share not only the base attributes but also an attribute called *description*, which is a string in both interfaces.
607
+
Now we know that both interfaces *CoursePartBasic* and *CoursePartBackground* share not only the base attributes but also an attribute called *description*, which is a string in both interfaces.
608
608
609
-
Your first task is to declare a new interface that includes the *description* attribute and extends the *CoursePartBase* interface. Then modify the code so that you can remove the *description* attribute from both *CoursePartBasic* and *CoursePartBackround* without getting any errors.
609
+
Your first task is to declare a new interface that includes the *description* attribute and extends the *CoursePartBase* interface. Then modify the code so that you can remove the *description* attribute from both *CoursePartBasic* and *CoursePartBackground* without getting any errors.
610
610
611
611
Then create a component *Part* that renders all attributes of each type of course part. Use a switch case-based exhaustive type checking! Use the new component in component *Content*.
0 commit comments