Skip to content

Commit 1bf7925

Browse files
jonathandsouzaj.dsouza
andauthored
Change "Nothing or All" to "All or Nothing" for poetic reasons. (#717)
* refactor: change "nothing or all" to "all or nothing" for poetic reasons. * fixed invalid prop def --------- Co-authored-by: j.dsouza <j.dsouza@freetimecompany.nl>
1 parent 3fcab91 commit 1bf7925

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

docs/advanced/patterns_by_usecase.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -714,19 +714,19 @@ const Component = () => (
714714

715715
[View in the TypeScript Playground](https://www.typescriptlang.org/play#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgIilQ3wChSYBPMJOABRzAGcBGOAXjgG84qaAuApggR8AbjjCIgpjCjAAdgHM4AXzEVqtBhGYAmDt15bB+AEYoo4uBagy5ilevJoIC2XADyCpJ6gAVAAtfGGCoQwAKMEYmQR1mNgAfehi9AEoOAD5uUjg4YEw4KJiAOj5adkqhEXwMrly8uAB6JrgAA2jdJhLbNrgAEwgkJjgFCHgkAA9gWQa8ohgAVygFOAAeTK5O5hKpVTWmzI081QaW9u3uqT7B4dHxuCmZmAaF5dWNrdLbfcONZ1c7ngAGFcJAfAp4JwIhl2NkIg0NnN1t5fAFgp5QkhwuV2PgpPhmtkuE0AFSPKA4cKkpqnRoonx+IIhMLGGh4gmSER4wmHbhkuAQADWcBpdMaa1RTIxWJxWg5NRslh5RP55OxVNFtORksZ6JZ2LZSAVoi5EBVthVfJJ6sp0C14ryurRzMxrNx5ksvOJAo19rFOql+rdho9tkJUitPttmoD9Od0oNcvZnqsSqgUbVgpFcYlQddsqNePDZotyvw3qzfup2qdh1IaTEQA).
716716

717-
## Props: Pass nothing or all
717+
## Props: Pass all or nothing
718718

719719
Passing no props is equivalent to passing an empty object. However, the type for an empty object is not `{}`, which you might think. [Make sure you understand what empty interface, `{}` and `Object` means](/docs/basic/getting-started/basic_type_example#empty-interface--and-object). `Record<string, never>` is probably the closest you can get to an empty object type, and is [recommended by typescript-eslint](https://typescript-eslint.io/rules/ban-types/). Here's an example of allowing "nothing or all":
720720

721721
```tsx
722-
type Nothing = Record<string, never>;
723-
724722
interface All {
725723
a: string;
726724
b: string;
727725
}
728726

729-
const NothingOrAll = (props: Nothing | All) => {
727+
type Nothing = Record<string, never>;
728+
729+
const AllOrNothing = (props: All | Nothing) => {
730730
if ("a" in props) {
731731
return <>{props.b}</>;
732732
}
@@ -735,10 +735,10 @@ const NothingOrAll = (props: Nothing | All) => {
735735

736736
const Component = () => (
737737
<>
738-
<NothingOrAll /> {/* ok */}
739-
<NothingOrAll a="" /> {/* error */}
740-
<NothingOrAll b="" /> {/* error */}
741-
<NothingOrAll a="" b="" /> {/* ok */}
738+
<AllOrNothing /> {/* ok */}
739+
<AllOrNothing a="" /> {/* error */}
740+
<AllOrNothing b="" /> {/* error */}
741+
<AllOrNothing a="" b="" /> {/* ok */}
742742
</>
743743
);
744744
```
@@ -753,7 +753,7 @@ interface Props {
753753
};
754754
}
755755

756-
const NothingOrAll = (props: Props) => {
756+
const AllOrNothing = (props: Props) => {
757757
if (props.obj) {
758758
return <>{props.obj.a}</>;
759759
}
@@ -762,10 +762,10 @@ const NothingOrAll = (props: Props) => {
762762

763763
const Component = () => (
764764
<>
765-
<NothingOrAll /> {/* ok */}
766-
<NothingOrAll obj={{ a: "" }} /> {/* error */}
767-
<NothingOrAll obj={{ b: "" }} /> {/* error */}
768-
<NothingOrAll obj={{ a: "", b: "" }} /> {/* ok */}
765+
<AllOrNothing /> {/* ok */}
766+
<AllOrNothing obj={{ a: "" }} /> {/* error */}
767+
<AllOrNothing obj={{ b: "" }} /> {/* error */}
768+
<AllOrNothing obj={{ a: "", b: "" }} /> {/* ok */}
769769
</>
770770
);
771771
```

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy