You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: pages/Advanced Types.md
+15-5Lines changed: 15 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -834,6 +834,10 @@ type Partial<T> = { [P in keyof T]?: T[P] }
834
834
835
835
In these examples, the properties list is `keyofT` and the resulting type is some variant of `T[P]`.
836
836
This is a good template for any general use of mapped types.
837
+
That's because this kind of transformation is [homomorphic](https://en.wikipedia.org/wiki/Homomorphism), which means that the mapping applies only to properties of `T` and no others.
838
+
The compiler knows that it can copy all the existing property modifiers before adding any new ones.
839
+
For example, if `Person.name` were readonly, `Partial<Person>.name` would be readonly and optional.
840
+
837
841
Here's one more example, in which `T[P]` is wrapped in a `Proxy<T>` class:
0 commit comments