Skip to content

Commit d5e6305

Browse files
committed
refactor exclusive type definition and improve usage examples
1 parent 2d95bb9 commit d5e6305

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

public/consolidated/typescript.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"typedefinition"
1313
],
1414
"contributors": [],
15-
"code": "type Exclusive<T, U = T> = T | U extends Record<string, unknown>\n ?\n | ({ [P in Exclude<keyof T, keyof U>]?: never } & U)\n | ({ [P in Exclude<keyof U, keyof T>]?: never } & T)\n : T | U;\n```\n\n# Usage:\n```ts\ntype A = { name: string; email?: string; provider?: string };\ntype B = { name: string; phone?: string; country?: string };\n\ntype EitherOr = Exclusive<A, B>;\n\nconst w: EitherOr = { name: \"John\", email: \"[email protected]\" }; // ✅\nconst x: EitherOr = { name: \"John\", phone: \"+123 456\" }; // ✅\nconst y: EitherOr = { name: \"John\", email: \"\", phone: \"\" }; // ⛔️\nconst z: EitherOr = { name: \"John\", phne: \"\", provider: \"\" }; // ⛔️\n`"
15+
"code": "type Exclusive<T, U = T> = T | U extends Record<string, unknown>\n ?\n | ({ [P in Exclude<keyof T, keyof U>]?: never } & U)\n | ({ [P in Exclude<keyof U, keyof T>]?: never } & T)\n : T | U;\n\n\n# Usage:\ntype A = { name: string; email?: string; provider?: string };\ntype B = { name: string; phone?: string; country?: string };\n\ntype EitherOr = Exclusive<A, B>;\n\nconst w: EitherOr = { name: \"John\", email: \"[email protected]\" }; // ✅\nconst x: EitherOr = { name: \"John\", phone: \"+123 456\" }; // ✅\nconst y: EitherOr = { name: \"John\", email: \"\", phone: \"\" }; // ⛔️\nconst z: EitherOr = { name: \"John\", phne: \"\", provider: \"\" }; // ⛔️\n"
1616
}
1717
]
1818
}

snippets/typescript/helper-types/exclusive-type.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ type Exclusive<T, U = T> = T | U extends Record<string, unknown>
1111
| ({ [P in Exclude<keyof T, keyof U>]?: never } & U)
1212
| ({ [P in Exclude<keyof U, keyof T>]?: never } & T)
1313
: T | U;
14-
```
14+
1515

1616
# Usage:
17-
```ts
1817
type A = { name: string; email?: string; provider?: string };
1918
type B = { name: string; phone?: string; country?: string };
2019

@@ -24,4 +23,4 @@ const w: EitherOr = { name: "John", email: "[email protected]" }; // ✅
2423
const x: EitherOr = { name: "John", phone: "+123 456" }; //
2524
const y: EitherOr = { name: "John", email: "", phone: "" }; // ⛔️
2625
const z: EitherOr = { name: "John", phne: "", provider: "" }; // ⛔️
27-
````
26+
```

0 commit comments

Comments
 (0)