The Built-In Transformations

Derive rather than duplicate. A near-copy of a type will eventually disagree with the original, in exactly the way a repeated author name disagrees in the SQL course. The utility types are how you avoid the copy.

Try it

Add a subtitle to Book and see it appear in BookPatch without you touching it.

loading editor…

checking…

The last line is rejected because BookDraft has no id. Add a field to Book and all three derived types follow automatically.

The ones worth knowing.

Partial<T> every property optional, for updates.

Required<T> the opposite.

Readonly<T> every property readonly.

Pick<T, K> only those properties.

Omit<T, K> all but those.

Record<K, V> an object with those keys and values.

ReturnType<typeof fn> whatever a function returns.

That is most of what you will use. The rest can wait until you meet them.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: typeof and keyof →
← Back