Skip to content

Commit a4ff7ed

Browse files
committed
Various fixes
1 parent ca74311 commit a4ff7ed

File tree

5 files changed

+32
-60
lines changed

5 files changed

+32
-60
lines changed

Diff for: book-content/chapters/04-essential-types-and-annotations.md

+2-25
Original file line numberDiff line numberDiff line change
@@ -1459,14 +1459,10 @@ There is currently an error under the type argument for `JSON.parse`.
14591459
A test that checks the type of `parsedData` is currently failing, since it is typed as `any` instead of the expected type:
14601460

14611461
```ts twoslash
1462-
// @errors: 2558 2344
1463-
import { it, expect } from "vitest";
1462+
// @errors: 2344
14641463
import { Expect, Equal } from "@total-typescript/helpers";
14651464

1466-
const parsedData = JSON.parse<{
1467-
name: string;
1468-
age: number;
1469-
}>('{"name": "Alice", "age": 30}');
1465+
declare const parsedData: any;
14701466

14711467
// ---cut---
14721468
type test = Expect<
@@ -1478,13 +1474,6 @@ type test = Expect<
14781474
}
14791475
>
14801476
>;
1481-
1482-
it("Should be the correct shape", () => {
1483-
expect(parsedData).toEqual({
1484-
name: "Alice",
1485-
age: 30,
1486-
});
1487-
});
14881477
```
14891478

14901479
We've tried to pass a type argument to the `JSON.parse` function. But it doesn't appear to be working in this case.
@@ -1923,21 +1912,9 @@ Here we have a `concatenate` function that takes in a variable number of strings
19231912

19241913
```ts twoslash
19251914
// @errors: 7019
1926-
import { Expect, Equal } from "@total-typescript/helpers";
1927-
import { it, expect } from "vitest";
1928-
1929-
// ---cut---
19301915
export function concatenate(...strings) {
19311916
return strings.join("");
19321917
}
1933-
1934-
it("should concatenate strings", () => {
1935-
const result = concatenate("Hello", " ", "World");
1936-
1937-
expect(result).toEqual("Hello World");
1938-
1939-
type test = Expect<Equal<typeof result, string>>;
1940-
});
19411918
```
19421919

19431920
The test passes, but there's an error on the `...strings` rest parameter.

Diff for: book-content/chapters/06-objects.md

+9-21
Original file line numberDiff line numberDiff line change
@@ -767,45 +767,33 @@ A test case that checks for numeric keys does have issues because the function i
767767

768768
```ts twoslash
769769
// @errors: 2345
770-
import { it, expect } from "vitest";
771770

772771
const hasKey = (obj: object, key: string) => {
773772
return obj.hasOwnProperty(key);
774773
};
775774

776775
// ---cut---
777-
it("Should work on number keys", () => {
778-
const obj = {
779-
1: "bar",
780-
};
781-
782-
expect(hasKey(obj, 1)).toBe(true);
783-
expect(hasKey(obj, 2)).toBe(false);
784-
});
776+
const obj = {
777+
1: "bar",
778+
};
785779
```
786780

787781
Because an object can also have a symbol as a key, there is also a test for that case. It currently has type errors for `fooSymbol` and `barSymbol` when calling `hasKey`:
788782

789783
```ts twoslash
784+
// @lib: dom,es2023,dom.iterable
790785
// @errors: 2345
791-
import { it, expect } from "vitest";
792-
793786
const hasKey = (obj: object, key: string) => {
794787
return obj.hasOwnProperty(key);
795788
};
796789

797790
// ---cut---
798-
it("Should work on symbol keys", () => {
799-
const fooSymbol = Symbol("foo");
800-
const barSymbol = Symbol("bar");
791+
const fooSymbol = Symbol("foo");
792+
const barSymbol = Symbol("bar");
801793

802-
const obj = {
803-
[fooSymbol]: "bar",
804-
};
805-
806-
expect(hasKey(obj, fooSymbol)).toBe(true);
807-
expect(hasKey(obj, barSymbol)).toBe(false);
808-
});
794+
const obj = {
795+
[fooSymbol]: "bar",
796+
};
809797
```
810798

811799
Your task is to update the `hasKey` function so that all of these tests pass. Try to be as concise as possible!

Diff for: book-content/chapters/11-annotations-and-assertions.md

+3
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ This `handleFormData` function accepts an argument `e` typed as `SubmitEvent`, w
572572
Within the function we use the method `e.preventDefault()`, available on `SubmitEvent`, to stop the form from its default submission action. Then we attempt to create a new `FormData` object, `data`, with `e.target`:
573573

574574
```ts twoslash
575+
// @lib: dom,es2023,dom.iterable
575576
// @errors: 2345
576577
const handleFormData = (e: SubmitEvent) => {
577578
e.preventDefault();
@@ -797,6 +798,7 @@ Your task is to update the `routes` object typing so that all errors are resolve
797798
The error we encountered in this challenge was that the `EventTarget | null` type was incompatible with the required parameter of type `HTMLFormElement`. The problem stems from the fact that these types don't match, and `null` is not permitted:
798799

799800
```ts twoslash
801+
// @lib: dom,es2023,dom.iterable
800802
// @errors: 2345
801803
const handleFormData = (e: SubmitEvent) => {
802804
e.preventDefault();
@@ -815,6 +817,7 @@ We can use the `as` keyword to recast `e.target` to a specific type.
815817
However, if we recast it as `EventTarget`, an error will continue to occur:
816818

817819
```ts twoslash
820+
// @lib: dom,es2023,dom.iterable
818821
// @errors: 2345
819822
const handleFormData = (e: SubmitEvent) => {
820823
e.preventDefault();

Diff for: package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"nodemon": "^3.0.1",
1313
"npm-run-all": "^4.1.5",
1414
"prettier": "^2.8.7",
15-
"typescript": "^5.4.5",
15+
"typescript": "^5.5.2",
1616
"vite-tsconfig-paths": "^4.0.7",
1717
"vitest": "^1.6.0"
1818
},
@@ -590,7 +590,11 @@
590590
"e-202.7": "tt-cli run 202.7",
591591
"s-202.7": "tt-cli run 202.7 --solution",
592592
"e-072.5": "tt-cli run 072.5",
593-
"s-072.5": "tt-cli run 072.5 --solution"
593+
"s-072.5": "tt-cli run 072.5 --solution",
594+
"e-034.5": "tt-cli run 034.5",
595+
"s-034.5": "tt-cli run 034.5 --solution",
596+
"e-066.5": "tt-cli run 066.5",
597+
"s-066.5": "tt-cli run 066.5 --solution"
594598
},
595599
"dependencies": {
596600
"@tanstack/react-query": "^4.29.12",

Diff for: pnpm-lock.yaml

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)