Skip to content

Commit 23fe0aa

Browse files
committed
Made updates to evolving any
1 parent a4ff7ed commit 23fe0aa

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

book-content/chapters/12-the-weird-parts.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,15 @@ This technique of using the evolving `any` also works with arrays. When you decl
3333

3434
```ts twoslash
3535
const evolvingArray = [];
36-
// ^?
3736

3837
evolvingArray.push("abc");
39-
// ^?
4038

41-
evolvingArray.push(123);
39+
const elem = evolvingArray[0];
4240
// ^?
4341

44-
evolvingArray.push("do re mi");
45-
// ^?
42+
evolvingArray.push(123);
4643

47-
evolvingArray.push({ easy: true });
44+
const elem2 = evolvingArray[1];
4845
// ^?
4946
```
5047

@@ -97,7 +94,7 @@ const processAlbum = (album: Album) => console.log(album);
9794
processAlbum({
9895
title: "Rubber Soul",
9996
releaseYear: 1965,
100-
label: "Parlophone", // red squiggly line under label
97+
label: "Parlophone",
10198
});
10299
```
103100

@@ -132,7 +129,7 @@ In this case, TypeScript won't show an error, and you won't get the runtime beha
132129
```ts twoslash
133130
// @errors: 2561
134131
const options: { timeout?: number } = {
135-
timeOut: 1000, // red squiggly line under timeOut
132+
timeOut: 1000,
136133
};
137134
```
138135

@@ -1016,7 +1013,7 @@ acceptAnythingExceptNullOrUndefined(
10161013

10171014
Your task is to add a type annotation to the `acceptAnythingExceptNullOrUndefined` function that will allow it to accept any value except `null` or `undefined`.
10181015

1019-
<Exercise title="Exercise 1: Accept Anything Except `null` and `undefined`" filePath="/src/050-the-weird-parts/150-empty-object-type.problem.ts"></Exercise>
1016+
<Exercise title="Exercise 1: Accept Anything Except `null` and `undefined`" filePath="/src/050-the-weird-parts/150-empty-object-type.problem.ts" resourceId="NMpTvrI4rUCyVa4GW2ViSR"></Exercise>
10201017

10211018
### Exercise 2: Detecting Excess Properties in an Object
10221019

@@ -1056,7 +1053,7 @@ myFetch(options);
10561053

10571054
Your challenge is to determine why the `@ts-expect-error` directive isn't working, and restructure the code so that it does. Try to solve it multiple ways!
10581055

1059-
<Exercise title="Exercise 2: Detecting Excess Properties in an Object" filePath="/src/050-the-weird-parts/152-excess-properties-warnings.problem.ts"></Exercise>
1056+
<Exercise title="Exercise 2: Detecting Excess Properties in an Object" filePath="/src/050-the-weird-parts/152-excess-properties-warnings.problem.ts" resourceId="PUZfccUL9g0ocvr45qbRoQ"></Exercise>
10601057

10611058
### Exercise 3: Detecting Excess Properties in a Function
10621059

@@ -1111,7 +1108,7 @@ Despite TypeScript not expecting an `age` on `User`, it doesn't show an error, a
11111108

11121109
Your task is to determine why TypeScript isn't raising an error in this case, and find two different solutions to make it error appropriately when an unexpected property is added.
11131110

1114-
<Exercise title="Exercise 3: Detecting Excess Properties in a Function" filePath="/src/050-the-weird-parts/153-excess-properties-warnings-in-functions.problem.ts"></Exercise>
1111+
<Exercise title="Exercise 3: Detecting Excess Properties in a Function" filePath="/src/050-the-weird-parts/153-excess-properties-warnings-in-functions.problem.ts" resourceId="PUZfccUL9g0ocvr45qbS8Y"></Exercise>
11151112

11161113
### Exercise 4: Iterating over Objects
11171114

@@ -1150,7 +1147,7 @@ Try to solve this exercise with a `for` loop for one solution, and `Object.keys(
11501147

11511148
Remember, `Object.keys()` is typed to always return an array of strings.
11521149

1153-
<Exercise title="Exercise 4: Iterating over Objects" filePath="/src/050-the-weird-parts/154.6-iterating-over-objects.problem.ts"></Exercise>
1150+
<Exercise title="Exercise 4: Iterating over Objects" filePath="/src/050-the-weird-parts/154.6-iterating-over-objects.problem.ts" resourceId="PUZfccUL9g0ocvr45qbSW2"></Exercise>
11541151

11551152
### Exercise 5: Function Parameter Comparisons
11561153

@@ -1202,7 +1199,6 @@ const listenToEvent = (callback: CallbackType) => {};
12021199

12031200
// ---cut---
12041201
listenToEvent((event, x, y) => {
1205-
// red squiggly line under event, x, and y
12061202
type tests = [
12071203
Expect<Equal<typeof event, Event>>,
12081204
Expect<Equal<typeof x, number>>,
@@ -1225,7 +1221,6 @@ const listenToEvent = (callback: CallbackType) => {};
12251221

12261222
// ---cut---
12271223
listenToEvent((event, x, y, screenId) => {
1228-
// red squiggly line under event, x, y, and screenId
12291224
type tests = [
12301225
Expect<Equal<typeof event, Event>>,
12311226
Expect<Equal<typeof x, number>>,
@@ -1239,7 +1234,7 @@ In almost every case, TypeScript is giving us errors.
12391234

12401235
Your task is to update the `CallbackType` to ensure that it can handle all of these cases.
12411236

1242-
<Exercise title="Exercise 5: Function Parameter Comparisons" filePath="/src/050-the-weird-parts/155-function-parameter-comparisons.problem.ts"></Exercise>
1237+
<Exercise title="Exercise 5: Function Parameter Comparisons" filePath="/src/050-the-weird-parts/155-function-parameter-comparisons.problem.ts" resourceId="jUJqrXCHRph0Z4Fs6VxI9r"></Exercise>
12431238

12441239
### Exercise 6: Unions of Functions with Object Params
12451240

@@ -1275,14 +1270,13 @@ const loggers = [logId, logName];
12751270

12761271
// ---cut---
12771272
const logAll = (obj) => {
1278-
// red squiggly line under obj
12791273
loggers.forEach((func) => func(obj));
12801274
};
12811275
```
12821276

12831277
Your task is to determine how to type the `obj` parameter to the `logAll` function. Look closely at the type signatures for the individual logger functions to understand what type this object should be.
12841278

1285-
<Exercise title="Exercise 6: Unions of Functions with Object Params" filePath="/src/050-the-weird-parts/156-unions-of-functions-with-object-params.problem.ts"></Exercise>
1279+
<Exercise title="Exercise 6: Unions of Functions with Object Params" filePath="/src/050-the-weird-parts/156-unions-of-functions-with-object-params.problem.ts" resourceId="NMpTvrI4rUCyVa4GW2ViZX"></Exercise>
12861280

12871281
### Exercise 7: Union of Functions With Incompatible Parameters
12881282

@@ -1334,7 +1328,7 @@ Currently there's an error on `input` in the return statement of the `format` fu
13341328

13351329
A useful tidbit - `any` is not assignable to `never`.
13361330

1337-
<Exercise title="Exercise 7: Union of Functions With Incompatible Parameters" filePath="/src/050-the-weird-parts/157-unions-of-functions.problem.ts"></Exercise>
1331+
<Exercise title="Exercise 7: Union of Functions With Incompatible Parameters" filePath="/src/050-the-weird-parts/157-unions-of-functions.problem.ts" resourceId="Mcr8ILwjCSlKdfKEBg8upM"></Exercise>
13381332

13391333
### Solution 1: Accept Anything Except `null` and `undefined`
13401334

0 commit comments

Comments
 (0)