Skip to content

Commit ca74311

Browse files
committed
Tweak to 04
1 parent 5f92659 commit ca74311

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,6 @@ Like before, TypeScript gives us an error when testing that the function returns
622622

623623
```ts twoslash
624624
// @errors: 2345
625-
import { it, expect } from "vitest";
626-
import { Expect, Equal } from "@total-typescript/helpers";
627-
628625
const concatName = (user: { first: string; last: string }) => {
629626
if (!user.last) {
630627
return user.first;
@@ -634,19 +631,11 @@ const concatName = (user: { first: string; last: string }) => {
634631
};
635632

636633
// ---cut---
637-
it("should only return the first name if last name not provided", () => {
638-
const result = concatName({
639-
first: "John",
640-
});
641-
642-
type test = Expect<Equal<typeof result, string>>;
643-
644-
expect(result).toEqual("John");
634+
const result = concatName({
635+
first: "John",
645636
});
646637
```
647638

648-
This time the entire `{first: "John"}` object is underlined in red.
649-
650639
The error tells us that we are missing a property, but the error is incorrect. We _do_ want to support objects that only include a `first` property. In other words, `last` needs to be optional.
651640

652641
How would you update this function to fix the errors?

0 commit comments

Comments
 (0)