Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adamrackis/chapter 10 #50

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions book-content/chapters/10-deriving-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ Instead, we can use the `number` type as the argument to the indexed access type

```typescript
type AllPrograms = (typeof programModes)[number];
// that's a new one for me - I did't know you could index tuple types with number. I'd urge you to cover that in the main content of the chapter, and, as I've said before, re-think whether you need these exercises in the book
```

Now new items can be added to the `programModes` array without needing to update the `AllPrograms` type manually. This solution makes the test pass as expected, and is a great pattern to apply in your own projects.
Expand Down Expand Up @@ -1417,6 +1418,8 @@ What can make decoupling a difficult decision is that deriving can make you feel

Deriving makes most sense when the code you're coupling shares a common concern. The examples in this chapter are good examples of this. Our `as const` object, for instance:

I think this discussion is missing a crucial component: sometimes you WANT coupling. If the AvatarImageProps from above doesn't just happen to contain some common properties from the User type, but is in fact, conceptually and in practice, a true subset of the User type, then you WANT tight coupling. If the imageUrl prop on the User type changes from a string to, say, a union of a string (url) or an object containing some inline preview for the image, then you want that change automatically propagated to the dervied type. Coupling is good and desirable sometimes. When it is, you should derive. When you just happen to have a type that shares some structure with another type, duplicate, don't derive.

```typescript
const albumTypes = {
CD: "cd",
Expand Down