Errata

Effective TypeScript

Errata for Effective TypeScript

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Item 15
Fourth code snippet of item

```
function parseCSV(input: string): {[columnName: string]: string}[] {
const lines = input.split('\n');
const [header, ...rows] = lines;
return rows.map(rowStr => {
const row: {[columnName: string]: string} = {};
rowStr.split(',').forEach((cell, i) => {
row[header[i]] = cell;
});
return row;
});
}
```

I believe this code snippet does not do what the author intended (mapping column names to values), as when `header[i]` is accessed, `header` is a string consisting of the entire header row. So given the following code:

```
console.log(parseCSV(`name,age
Will,23`))
```

The output will be:

```
[{
'n': 'Will',
'a': 23,
}]
```

Rather than what I suspect the author intended:

```
[{
'name': 'Will',
'age': 23,
}]
```

Fixed by:

```
function parseCSV(input: string): {[columnName: string]: string}[] {
const lines = input.split('\n');
const [header, ...rows] = lines;
const headerColumns = header.split(',');
return rows.map(rowStr => {
const row: {[columnName: string]: string} = {};
rowStr.split(',').forEach((cell, i) => {
row[headerColumns[i]] = cell;
});
return row;
});
}
```

Very minor!

(apologies for not listing page number: O'Reilly web viewer does not give an option to display them afaik)

Note from the Author or Editor:
Yes, this is a mistake. The header row needs to be split before being used for column names. (This is why you need tests, not just types!)

Will JV Smith  Feb 21, 2021 
Printed
Page 63
bottom of note

The text says "For a particularly useful variation on this, see inferringPick in Item 26." But Item 26 makes no mention of "inferringPick" (it was removed during editing).

(If you're curious, search for "inferPick" on my LogRocket post: https://blog.logrocket.com/how-typescript-breaks-referential-transparency-7a82c0345f2c/)

Dan Vanderkam
 
Jun 09, 2020 
Printed
Page 68
First code example

Last line of the code example is:

{ '1,2,3': 1 }

The value should be 2, not 1:

{ '1,2,3': 2 }

Stein Magnus Jodal  Mar 20, 2020 
Printed
Page 100
First code example

Line 4 is:

pt.y < polygon.bbox.y[1] || pt.y > polygon.bbox.y[1]) {

The index in the lower bound check should be 0, not 1:

pt.y < polygon.bbox.y[0] || pt.y > polygon.bbox.y[1]) {

Note from the Author or Editor:
This has been fixed in the second release (March 2020).

Stein Magnus Jodal  Mar 23, 2020  Mar 06, 2020
Printed
Page 101
Second code example

Line 6 is:

pt.y < x[0] || pt.y > y[1]) {

Instead of comparing with the lower x boundary, it should compare with the lower y boundary:

pt.y < y[0] || pt.y > y[1]) {

Note from the Author or Editor:
This has been fixed in the second release.

Stein Magnus Jodal  Mar 23, 2020  Mar 06, 2020
Printed
Page 103
bottom paragraph

This is a sentence fragment: "Within an async function, awaiting a Promise that throws an exception."

It should read: "Within an async function, awaiting a Promise that *rejects* throws an exception."

Dan Vanderkam
 
Jan 26, 2020  Mar 06, 2020
Printed
Page 114
4th and 5th code example

To illustrate the "chain" concept in Lodash/Underscore, two code examples are shown, intended to have an equivalent effect.

The traditional version:

_.a(_.b(_.c(v)))

The chained version:

_(v).a().b().c().value()

For these to be equivalent, the order of a/b/c must be switched in one of the examples, e.g.:

_.c(_.b(_.a(v))) and _(v).a().b().c().value()

or:

_.a(_.b(_.c(v))) and _(v).c().b().a().value()

Note from the Author or Editor:
The intent was

_.c(_.b(_.a(v))) and _(v).a().b().c().value()

I've fixed this in the book repo.

Stein Magnus Jodal  Apr 13, 2020 
Printed
Page 136
Second code example

The code example is:

function pluck(records, key) {
return record.map(record => record[key]);
}

The argument is `records` in plural, while the variable that is mapped over is the undefined `record`, which also is shadowed in the arrow function. A working version would be:

function pluck(records, key) {
return records.map(record => record[key]);
}

To align with the following examples, it could be changed to:

function pluck(record, key) {
return record.map(r => r[key]);
}

Though I'd argue that the argument is an array, it should be named `records`, not `record` throughout all the examples.

Note from the Author or Editor:
They should all be `records` not `record`. I've made the fix and this will appear in the next release.

Stein Magnus Jodal  Apr 23, 2020 
Page 144
second code snippet

const geometryHelper = (g: Geometry) => {
if (geometry.type === 'GeometryCollection') {
...

the parameter defined as `g` but used as `geometry`

Note from the Author or Editor:
`geometry` should be `g` inside the body of `geometryHelper`. JavaScript scoping: always confusing, always error prone!

Yifan Pan  Oct 06, 2022 
Printed
Page 151
bottom code sample

The isSorted code sample reads:

if (xs[i] > xs[i - 1]) {
return false;
}

It should be "<", not ">".

Dan Vanderkam
 
Nov 18, 2019  Mar 06, 2020
Printed
Page 173
Continuation of the example from page 172

devDependencies should include @types/react

Note from the Author or Editor:
@types/lodash should be @types/react. Thanks for catching this mistake!

Anonymous  Jan 06, 2020  Mar 06, 2020
Page 194 Enums
3rd bullet

PDF is First Edition, Third Release (2021-07-16).

The text says, "If you changed to const enum Flavor in the previous example, the compiler would rewrite Flavor.CHOCOLATE as 0." However I'm pretty sure the value should be "1" instead of "0".

Note from the Author or Editor:
Should read "the compiler would rewrite Flavor.CHOCOLATE as 1."

David Hull  Dec 13, 2022 
Printed
Page 226
2nd paragraph, 3rd line

"properties" is misspelled "proprties".

Stein Magnus Josh  Nov 20, 2020  Jun 16, 2021
Printed
Page 228
5th paragraph

`npm install --sav-dev ...` should be `npm install --save-dev ...`.

Stein Magnus Jodal  Nov 20, 2020