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
The `this` keyword refers to the instance of the class, and it's used to access the properties and methods of the class.
100
100
101
-
Now, when we create a new instance of the `Album` class, we can pass an object with the properties we want to set. If we don't provide any values, the default values will be used:
101
+
Now, when we create a new instance of the `Album` class, we can pass an object with the properties we want to set.
102
102
103
103
```typescript
104
104
const loopFindingJazzRecords =newAlbum({
@@ -108,10 +108,6 @@ const loopFindingJazzRecords = new Album({
108
108
});
109
109
110
110
console.log(loopFindingJazzRecords.title); // Output: Loop Finding Jazz Records
111
-
112
-
const unknownAlbum =newAlbum();
113
-
114
-
console.log(unknownAlbum.title); // Output: Unknown Album
@@ -555,7 +555,7 @@ We want to use the `Environment` type across our application. However, the `conf
555
555
556
556
Your task is to update the `Environment` type so that it is derived from the `configurations` object.
557
557
558
-
<Exercisetitle="Exercise 2: Derive a Type from a Value"filePath="/src/040-deriving-types-from-values/126-typeof-keyword.problem.ts"></Exercise>
558
+
<Exercisetitle="Exercise 2: Derive a Type from a Value"filePath="/src/040-deriving-types-from-values/126-typeof-keyword.problem.ts"resourceId="YgFRxBViy44CfW0H6uOMPr"></Exercise>
559
559
560
560
### Exercise 3: Accessing Specific Values
561
561
@@ -587,7 +587,7 @@ type test = Expect<Equal<Group, "group">>;
587
587
588
588
Your task is to find the proper way to type `Group` so the test passes as expected.
589
589
590
-
<Exercisetitle="Exercise 3: Accessing Specific Values"filePath="/src/040-deriving-types-from-values/135-indexed-access-types.problem.ts"></Exercise>
590
+
<Exercisetitle="Exercise 3: Accessing Specific Values"filePath="/src/040-deriving-types-from-values/135-indexed-access-types.problem.ts"resourceId="5EnWog8KD1gKEzaFObJmOY"></Exercise>
591
591
592
592
### Exercise 4: Unions with Indexed Access Types
593
593
@@ -617,7 +617,7 @@ type test = Expect<
617
617
618
618
This time, your challenge is to update the `PlannedPrograms` type to use an indexed access type to extract a union of the `ProgramModeMap` values that included "`planned`".
619
619
620
-
<Exercisetitle="Exercise 4: Unions with Indexed Access Types"filePath="/src/040-deriving-types-from-values/136-pass-unions-to-indexed-access-types.problem.ts"></Exercise>
620
+
<Exercisetitle="Exercise 4: Unions with Indexed Access Types"filePath="/src/040-deriving-types-from-values/136-pass-unions-to-indexed-access-types.problem.ts"resourceId="5EnWog8KD1gKEzaFObJmhp"></Exercise>
621
621
622
622
### Exercise 5: Extract a Union of All Values
623
623
@@ -658,7 +658,7 @@ type test = Expect<
658
658
659
659
Using what you've learned so far, your task is to update the `AllPrograms` type to use an indexed access type to create a union of all the values from the `programModeEnumMap` object.
660
660
661
-
<Exercisetitle="Exercise 5: Extract a Union of All Values"filePath="/src/040-deriving-types-from-values/137-pass-keyof-into-an-indexed-access-type.problem.ts"></Exercise>
661
+
<Exercisetitle="Exercise 5: Extract a Union of All Values"filePath="/src/040-deriving-types-from-values/137-pass-keyof-into-an-indexed-access-type.problem.ts"resourceId="VtQChjOYAJCkX9MVx78MCb"></Exercise>
662
662
663
663
### Exercise 6: Create a Union from an `as const` Array
664
664
@@ -681,6 +681,7 @@ A test has been written to check if an `AllPrograms` type is a union of all the
@@ -698,7 +699,7 @@ Your task is to determine how to create the `AllPrograms` type in order for the
698
699
699
700
Note that just using `keyof` and `typeof` in an approach similar to the previous exercise's solution won't quite work to solve this one! This is tricky to find - but as a hint: you can pass primitive types to indexed access types.
700
701
701
-
<Exercisetitle="Exercise 6: Create a Union from an `as const` Array"filePath="/src/040-deriving-types-from-values/138-create-a-union-from-an-as-const-array.problem.ts"></Exercise>
702
+
<Exercisetitle="Exercise 6: Create a Union from an `as const` Array"filePath="/src/040-deriving-types-from-values/138-create-a-union-from-an-as-const-array.problem.ts"resourceId="AhnoaCs5v1qlRT7GjJoi5Y"></Exercise>
702
703
703
704
### Solution 1: Reduce Key Repetition
704
705
@@ -1050,7 +1051,7 @@ In addition to being a bit annoying to write and read, the other problem with th
1050
1051
1051
1052
Your task is to use a utility type to fix this problem.
1052
1053
1053
-
<Exercise title="Exercise 7: A Single Source of Truth" filePath="/src/040-deriving-types-from-values/132-parameters-type-helper.problem.ts"></Exercise>
1054
+
<Exercise title="Exercise 7: A Single Source of Truth" filePath="/src/040-deriving-types-from-values/132-parameters-type-helper.problem.ts" resourceId="YgFRxBViy44CfW0H6uOO1f"></Exercise>
1054
1055
1055
1056
### Exercise 8: Typing Based on Return Value
1056
1057
@@ -1090,7 +1091,7 @@ type test = Expect<
1090
1091
1091
1092
Your task is to update the `User` type so the test passes as expected.
1092
1093
1093
-
<Exercise title="Exercise 8: Typing Based on Return Value" filePath="/src/040-deriving-types-from-values/133-return-type.problem.ts"></Exercise>
1094
+
<Exercise title="Exercise 8: Typing Based on Return Value" filePath="/src/040-deriving-types-from-values/133-return-type.problem.ts" resourceId="YgFRxBViy44CfW0H6uOPRx"></Exercise>
1094
1095
1095
1096
### Exercise 9: Unwrapping a Promise
1096
1097
@@ -1124,7 +1125,7 @@ Like before, assume that you do not have access to the implementation of the `fe
1124
1125
1125
1126
Your task is to update the `User` type so the test passes as expected.
1126
1127
1127
-
<Exercise title="Exercise 9: Unwrapping a Promise" filePath="/src/040-deriving-types-from-values/134-awaited-type-helper.problem.ts"></Exercise>
1128
+
<Exercise title="Exercise 9: Unwrapping a Promise" filePath="/src/040-deriving-types-from-values/134-awaited-type-helper.problem.ts" resourceId="AhnoaCs5v1qlRT7GjJofuY"></Exercise>
1128
1129
1129
1130
### Solution 7: A Single Source of Truth
1130
1131
@@ -1340,7 +1341,7 @@ Similarly to `Exclude`, `Extract` works by pattern matching. It will extract any
1340
1341
1341
1342
This means that, to reverse our `Extract` example earlier, we can use it to extract all strings from a union:
Copy file name to clipboardExpand all lines: book-content/chapters/14-configuring-typescript.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -141,7 +141,7 @@ This code will error in your target environment, because `target` won't transfor
141
141
142
142
If you're not sure what to specify for `target`, keep it up to date with the version you have specified in `lib`.
143
143
144
-
###`esModuleInterop`
144
+
###`esModuleInterop`
145
145
146
146
`esModuleInterop` is an old flag, released in 2018. It helps with interoperability between CommonJS and ES modules. At the time, TypeScript had deviated slightly from commonly-used tools like Babel in how it handled wildcard imports and default exports. `esModuleInterop` brought TypeScript in line with these tools.
//TypeError: Cannot read property 'toUpperCase' of undefined
245
245
```
246
246
247
247
By setting `noUncheckedIndexedAccess` to `true`, TypeScript will infer the type of every indexed access to be `T | undefined` instead of just `T`. In this case, every entry in `egoMirror.tracks` would be of type `string | undefined`:
0 commit comments