Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 8938679

Browse files
committed
Address PR comments
1 parent 4e13289 commit 8938679

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pages/Advanced Types.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ type Partial<T> = { [P in keyof T]?: T[P] }
834834
835835
In these examples, the properties list is `keyof T` and the resulting type is some variant of `T[P]`.
836836
This is a good template for any general use of mapped types.
837-
That's because this kind of transformation is homomorphic, which means that the mapping applies to every property of `T` and no others.
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.
838838
The compiler knows that it can copy all the existing property modifiers before adding any new ones.
839839
For example, if `Person.name` were readonly, `Partial<Person>.name` would be readonly and optional.
840840
@@ -865,15 +865,14 @@ type Record<K extends string | number, T> = {
865865
}
866866
```
867867
868-
`Readonly` and `Partial` are homomorphic whereas `Pick` and `Record` are not.
869-
One clue that `Pick` and `Record` are not homomorphic is that they both take a union of property names:
868+
`Readonly`, `Partial` and `Pick` are homomorphic whereas `Record` is not.
869+
One clue that `Record` is not homomorphic is that it doesn't take an input type to copy properties from:
870870
871871
```ts
872872
type ThreeStringProps = Record<'prop1' | 'prop2' | 'prop3', string>
873-
type PersonJustName = Pick<Person, 'name'>;
874873
```
875874
876-
These non-homomorphic types are essentially creating new properties (even though `Pick` uses `Person` as a source), so they don't copy property modifiers from anywhere; if `Person.name` were readonly, `Pick<Person, 'name'>.name` would not be readonly.
875+
Non-homomorphic types are essentially creating new properties, so they can't copy property modifiers from anywhere.
877876
878877
## Inference from mapped types
879878
@@ -892,5 +891,5 @@ function unproxify<T>(t: Proxify<T>): T {
892891
let originalProps = unproxify(proxyProps);
893892
```
894893

895-
Note that this unwrapping inference works best on homomorphic mapped types.
896-
If the mapped type is not homomorphic you might have to explicitly give a type parameter to your unwrapping function.
894+
Note that this unwrapping inference only works on homomorphic mapped types.
895+
If the mapped type is not homomorphic you will have to explicitly give a type parameter to your unwrapping function.

0 commit comments

Comments
 (0)