Skip to content

Commit 6a92934

Browse files
committed
tweaks
1 parent 2d9b482 commit 6a92934

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

src/content/9/en/part9d.md

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -547,64 +547,67 @@ which tells us that we are using a variable somewhere where it should never be u
547547
Let us now continue extending the app created in exercise 9.14. First, add the type information and replace the variable *courseParts* with the one from the example below.
548548
549549
```js
550-
// new types
551550
interface CoursePartBase {
552551
name: string;
553552
exerciseCount: number;
554-
type: string;
555553
}
556554

557-
interface CourseNormalPart extends CoursePartBase {
558-
type: "normal";
555+
interface CoursePartBasic extends CoursePartBase {
559556
description: string;
557+
kind: "basic"
560558
}
561559

562-
interface CourseProjectPart extends CoursePartBase {
563-
type: "groupProject";
560+
interface CoursePartGroup extends CoursePartBase {
564561
groupProjectCount: number;
562+
kind: "group"
565563
}
566564

567-
interface CourseSubmissionPart extends CoursePartBase {
568-
type: "submission";
565+
interface CoursePartBackround extends CoursePartBase {
569566
description: string;
570-
exerciseSubmissionLink: string;
567+
backroundMaterial: string;
568+
kind: "background"
571569
}
572570

573-
type CoursePart = CourseNormalPart | CourseProjectPart | CourseSubmissionPart;
571+
type CoursePart = CoursePartBasic | CoursePartGroup | CoursePartBackround;
574572

575-
// this is the new coursePart variable
576573
const courseParts: CoursePart[] = [
577574
{
578575
name: "Fundamentals",
579576
exerciseCount: 10,
580-
description: "This is the easy course part",
581-
type: "normal"
577+
description: "This is an awesome course part",
578+
kind: "basic"
582579
},
583580
{
584-
name: "Advanced",
581+
name: "Using props to pass data",
585582
exerciseCount: 7,
586-
description: "This is the hard course part",
587-
type: "normal"
583+
groupProjectCount: 3,
584+
kind: "group"
588585
},
589586
{
590-
name: "Using props to pass data",
587+
name: "Basics of type Narrowing",
591588
exerciseCount: 7,
592-
groupProjectCount: 3,
593-
type: "groupProject"
589+
description: "How to go from unknown to string",
590+
kind: "basic"
594591
},
595592
{
596593
name: "Deeper type usage",
597594
exerciseCount: 14,
598595
description: "Confusing description",
599-
exerciseSubmissionLink: "https://fake-exercise-submit.made-up-url.dev",
600-
type: "submission"
601-
}
602-
]
596+
backroundMaterial: "https://type-level-typescript.com/template-literal-types",
597+
kind: "background"
598+
},
599+
{
600+
name: "TypeScript in frontend",
601+
exerciseCount: 10,
602+
description: "a hard part",
603+
kind: "basic",
604+
},
605+
];
603606
```
604607
605-
Now we know that both interfaces *CourseNormalPart* and *CourseSubmissionPart* share not only the base attributes but also an attribute called *description*, which is a string in both interfaces.
608+
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.
606609
607-
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 *CourseNormalPart* and *CourseSubmissionPart* without getting any errors.
610+
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.
608611
609612
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*.
610613
@@ -616,7 +619,7 @@ Lastly, add another course part interface with the following attributes: *name*,
616619
exerciseCount: 21,
617620
description: "Typing the backend",
618621
requirements: ["nodejs", "jest"],
619-
type: "special"
622+
kind: "special"
620623
}
621624
```
622625

0 commit comments

Comments
 (0)