@visulima/tui 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE.md +130 -1
  3. package/dist/components/box.d.ts +735 -3
  4. package/dist/components/box.js +1 -1
  5. package/dist/components/canvas.js +1 -1
  6. package/dist/components/cursor.d.ts +2 -3
  7. package/dist/components/cursor.js +1 -1
  8. package/dist/components/error-overview.js +1 -1
  9. package/dist/components/spacer.js +1 -1
  10. package/dist/components/static-render.d.ts +2 -3
  11. package/dist/components/static-render.js +1 -1
  12. package/dist/components/static.d.ts +1 -3
  13. package/dist/components/static.js +1 -1
  14. package/dist/components/text.d.ts +1 -3
  15. package/dist/components/text.js +1 -1
  16. package/dist/components/transform.js +1 -1
  17. package/dist/core/index.js +1 -1
  18. package/dist/ink/canvas/index.d.ts +14 -1
  19. package/dist/ink/canvas/index.js +1 -1
  20. package/dist/ink/hooks/use-animation.js +1 -1
  21. package/dist/ink/hooks/use-app.d.ts +1 -2
  22. package/dist/ink/hooks/use-app.js +1 -1
  23. package/dist/ink/hooks/use-box-metrics.d.ts +2 -3
  24. package/dist/ink/hooks/use-box-metrics.js +1 -1
  25. package/dist/ink/hooks/use-clipboard.js +1 -1
  26. package/dist/ink/hooks/use-color-blindness.js +1 -1
  27. package/dist/ink/hooks/use-console-capture.js +1 -1
  28. package/dist/ink/hooks/use-cursor.d.ts +0 -1
  29. package/dist/ink/hooks/use-cursor.js +1 -1
  30. package/dist/ink/hooks/use-focus-manager.d.ts +0 -1
  31. package/dist/ink/hooks/use-focus-manager.js +1 -1
  32. package/dist/ink/hooks/use-focus.js +1 -1
  33. package/dist/ink/hooks/use-form.js +1 -1
  34. package/dist/ink/hooks/use-hotkey.js +1 -1
  35. package/dist/ink/hooks/use-input.js +2 -2
  36. package/dist/ink/hooks/use-interval.js +1 -1
  37. package/dist/ink/hooks/use-key-bindings.js +1 -1
  38. package/dist/ink/hooks/use-key-chord.js +1 -1
  39. package/dist/ink/hooks/use-paste.js +1 -1
  40. package/dist/ink/hooks/use-persistent-state.js +2 -2
  41. package/dist/ink/hooks/use-scroll-acceleration.js +1 -1
  42. package/dist/ink/hooks/use-scroll-input.js +1 -1
  43. package/dist/ink/hooks/use-stderr.d.ts +0 -1
  44. package/dist/ink/hooks/use-stderr.js +1 -1
  45. package/dist/ink/hooks/use-stdin.d.ts +0 -1
  46. package/dist/ink/hooks/use-stdin.js +1 -1
  47. package/dist/ink/hooks/use-stdout.d.ts +0 -1
  48. package/dist/ink/hooks/use-stdout.js +1 -1
  49. package/dist/ink/hooks/use-stopwatch.js +1 -1
  50. package/dist/ink/hooks/use-terminal-palette.d.ts +1 -1
  51. package/dist/ink/hooks/use-terminal-palette.js +1 -1
  52. package/dist/ink/hooks/use-text-buffer.js +4 -4
  53. package/dist/ink/hooks/use-text-selection.d.ts +3 -4
  54. package/dist/ink/hooks/use-text-selection.js +1 -1
  55. package/dist/ink/hooks/use-timeout.js +1 -1
  56. package/dist/ink/hooks/use-timer.js +1 -1
  57. package/dist/ink/hooks/use-window-size.js +1 -1
  58. package/dist/ink/index.d.ts +23 -15
  59. package/dist/ink/index.js +1 -1
  60. package/dist/ink/mouse/use-element-position.d.ts +2 -3
  61. package/dist/ink/mouse/use-element-position.js +1 -1
  62. package/dist/ink/mouse/use-mouse-action.d.ts +1 -2
  63. package/dist/ink/mouse/use-mouse-action.js +1 -1
  64. package/dist/ink/mouse/use-mouse-position.d.ts +1 -2
  65. package/dist/ink/mouse/use-mouse-position.js +1 -1
  66. package/dist/ink/mouse/use-mouse.d.ts +1 -2
  67. package/dist/ink/mouse/use-mouse.js +1 -1
  68. package/dist/ink/mouse/use-on-mouse-click.d.ts +3 -4
  69. package/dist/ink/mouse/use-on-mouse-click.js +1 -1
  70. package/dist/ink/mouse/use-on-mouse-hover.d.ts +2 -3
  71. package/dist/ink/mouse/use-on-mouse-hover.js +1 -1
  72. package/dist/ink/mouse/use-on-mouse-state.d.ts +2 -3
  73. package/dist/ink/mouse/use-on-mouse-state.js +1 -1
  74. package/dist/ink/public/cursor.d.ts +22 -1
  75. package/dist/ink/public/cursor.js +1 -1
  76. package/dist/ink/public/dom.d.ts +2 -3
  77. package/dist/ink/public/highlighter.d.ts +49 -3
  78. package/dist/ink/public/highlighter.js +1 -1
  79. package/dist/ink/public/input.d.ts +19 -1
  80. package/dist/ink/public/styles.d.ts +1 -3
  81. package/dist/ink/public/utils.d.ts +8 -1
  82. package/dist/ink/public/utils.js +1 -1
  83. package/dist/packem_shared/COLOR_BLINDNESS_COMPENSATION-CaI93Rjj.js +1 -0
  84. package/dist/packem_shared/Cell-CbDQUAjW.js +1 -0
  85. package/dist/packem_shared/DevTools-DKYxA_wO.js +1 -0
  86. package/dist/packem_shared/FocusContext-mWFBWdli.js +1 -0
  87. package/dist/packem_shared/Fullscreen-DKKMVbkg.js +1 -0
  88. package/dist/packem_shared/{IMECompositionBuffer-VhC9HRCv.js → IMECompositionBuffer-uYiAz3jI.js} +1 -1
  89. package/dist/packem_shared/{InputParser-CUAGWKQQ.js → InputParser-O4nyWUuQ.js} +2 -2
  90. package/dist/packem_shared/{KEY-C--kOw41.js → KEY-DGV_trPu.js} +1 -1
  91. package/dist/packem_shared/LayoutNode-D4i45GQM.js +1 -0
  92. package/dist/packem_shared/MouseProvider-BSTuFqG9.js +1 -0
  93. package/dist/packem_shared/NAMED_COLORS-DvfPALxN.js +1 -0
  94. package/dist/packem_shared/Range-CMqYzhij.js +1 -0
  95. package/dist/packem_shared/Renderer-Dg5_-6TF.js +1 -0
  96. package/dist/packem_shared/ResizeObserver-ClWoCtGV.js +1 -0
  97. package/dist/packem_shared/Static-sqw4n2Fv.js +1 -0
  98. package/dist/packem_shared/{TuiApp-CCVaiKbf.js → TuiApp-D1How6sn.js} +1 -1
  99. package/dist/packem_shared/TuiContext-Bbq9JRCu.js +3 -0
  100. package/dist/packem_shared/animation-context-Icwf5tBE.js +1 -0
  101. package/dist/packem_shared/ansi-parser-CysVDsNz.js +1 -0
  102. package/dist/packem_shared/ansi-tokenizer-D5k5LzXg.js +1 -0
  103. package/dist/packem_shared/{app-context-DTm1_XBA.js → app-context-CfgsW0CV.js} +1 -1
  104. package/dist/packem_shared/{app-context.d-DMLw5Nxy.d.ts → app-context.d-DAF6oxKX.d.ts} +0 -1
  105. package/dist/packem_shared/{boxes-DyY_LXCi.js → boxes-CidWUOVk.js} +1 -1
  106. package/dist/packem_shared/buildCursorOnlySequence-D24o0D7-.js +1 -0
  107. package/dist/packem_shared/calculateScroll-jdxVlcmq.js +1 -0
  108. package/dist/packem_shared/calculateScrollbarLayout-DCVwJ0Cl.js +1 -0
  109. package/dist/packem_shared/clearOsc52-olbKg5Nw.js +1 -0
  110. package/dist/packem_shared/clearStringWidthCache-EWeHQcEb.js +1 -0
  111. package/dist/packem_shared/colorize-Dsbi0Wr0.js +1 -0
  112. package/dist/packem_shared/createBrailleGrid-B5uefhi4.js +1 -0
  113. package/dist/packem_shared/createCanvasBuffer-C7w6bGe4.js +1 -0
  114. package/dist/packem_shared/createInlineLoop-BPlBAXqd.js +2 -0
  115. package/dist/packem_shared/createScreen-BBvF-ZyU.js +3 -0
  116. package/dist/packem_shared/cursor-context-wLwblh2o.js +1 -0
  117. package/dist/packem_shared/{disposeHighlighter-D9OkrhwX.js → disposeHighlighter-BS4lDPP8.js} +1 -1
  118. package/dist/packem_shared/dom-xpeZzKuf.js +1 -0
  119. package/dist/packem_shared/{dom.d-CLGlidfI.d.ts → dom.d-BV2bnRcH.d.ts} +2 -3
  120. package/dist/packem_shared/{focus-context-CsT69klR.js → focus-context-8h3hmNxy.js} +1 -1
  121. package/dist/packem_shared/formatDuration-DcLMLZro.js +1 -0
  122. package/dist/packem_shared/getPathToRoot-DBqZKIzf.js +1 -0
  123. package/dist/packem_shared/index-7Qq5uu0d.js +75 -0
  124. package/dist/packem_shared/isIntersecting-C8tJIsvH.js +1 -0
  125. package/dist/packem_shared/isTerminalPaletteQuerySupported-X6YXYjSp.js +1 -0
  126. package/dist/packem_shared/kittyFlags-jpd_IAFL.js +1 -0
  127. package/dist/packem_shared/load-native-root-binding-B1WunHs4.js +1 -0
  128. package/dist/packem_shared/measure-element-pHwUPovG.js +1 -0
  129. package/dist/packem_shared/measure-text-DtlK6gar.js +3 -0
  130. package/dist/packem_shared/mouse-context-BEnaR3tG.js +1 -0
  131. package/dist/packem_shared/{mouse-context.d-W-nszUps.d.ts → mouse-context.d-5TGeZyIF.d.ts} +1 -2
  132. package/dist/packem_shared/parseSgrMouse-CHYo9gs6.js +1 -0
  133. package/dist/packem_shared/probe-terminal-mMqobBjP.js +1 -0
  134. package/dist/packem_shared/processLayout-DYdx6C3A.js +2 -0
  135. package/dist/packem_shared/reconciler-BPm7fZa6.js +1 -0
  136. package/dist/packem_shared/reconciler-DXp9qy6k.js +1 -0
  137. package/dist/packem_shared/render-B_NqU7AH.js +1 -0
  138. package/dist/packem_shared/render-DGiSemZa.js +22 -0
  139. package/dist/packem_shared/{render.d-DjQhFsiN.d.ts → render.d-tqP_-Le_.d.ts} +43 -43
  140. package/dist/packem_shared/renderToString-BLr8QvYq.js +2 -0
  141. package/dist/packem_shared/renderToString-D66vRHLQ.js +4 -0
  142. package/dist/packem_shared/renderToken-DFWLdYz_.js +1 -0
  143. package/dist/packem_shared/renderTreeToBuffer-MEHvKJc-.js +2 -0
  144. package/dist/packem_shared/renderer-D97BmOBO.js +17 -0
  145. package/dist/packem_shared/{selection.d-BSAWa4ey.d.ts → selection.d-DCMpXtpU.d.ts} +1 -1
  146. package/dist/packem_shared/squashTextNodesWithMap-CUJZZeW3.js +1 -0
  147. package/dist/packem_shared/stderr-context-Xeacf3Ir.js +1 -0
  148. package/dist/packem_shared/stdin-context-Ceh-YuU1.js +1 -0
  149. package/dist/packem_shared/stdout-context-BhxOwdNK.js +1 -0
  150. package/dist/packem_shared/{styles.d-CKGQFfm4.d.ts → styles.d-BCZOPl_g.d.ts} +37 -3
  151. package/dist/packem_shared/terminal-palette.d-DSgSpnMs.d.ts +44 -0
  152. package/dist/packem_shared/text-width-BXmBaLDv.js +2 -0
  153. package/dist/packem_shared/utils-BlDbvbdr.js +1 -0
  154. package/dist/packem_shared/waitFor-BjdYqkin.js +4 -0
  155. package/dist/packem_shared/wrapOrTruncateStyledLine-Gm21gYDr.js +3 -0
  156. package/dist/react/index.d.ts +1 -1
  157. package/dist/react/index.js +1 -1
  158. package/dist/testing/index.d.ts +4 -6
  159. package/dist/testing/index.js +1 -1
  160. package/index.js +26 -26
  161. package/package.json +13 -13
  162. package/dist/packem_shared/COLOR_BLINDNESS_COMPENSATION-Ilnoyeqc.js +0 -1
  163. package/dist/packem_shared/Cell-BrXn3jxY.js +0 -1
  164. package/dist/packem_shared/DevTools-CZ-O0Ckm.js +0 -1
  165. package/dist/packem_shared/FocusContext-BWFqf9kb.js +0 -1
  166. package/dist/packem_shared/Fullscreen-BRhuBLBh.js +0 -1
  167. package/dist/packem_shared/LayoutNode-LPYsuzBg.js +0 -1
  168. package/dist/packem_shared/MouseProvider-DOcWCRVq.js +0 -1
  169. package/dist/packem_shared/NAMED_COLORS-82DpREQV.js +0 -1
  170. package/dist/packem_shared/Range-BsVYNWtg.js +0 -1
  171. package/dist/packem_shared/Renderer-BeS49FNq.js +0 -1
  172. package/dist/packem_shared/ResizeObserver-BI9bDy-j.js +0 -1
  173. package/dist/packem_shared/Static-DSzsElz4.js +0 -1
  174. package/dist/packem_shared/TuiContext-BNmP0lMY.js +0 -3
  175. package/dist/packem_shared/animation-context-DW3p-vpk.js +0 -1
  176. package/dist/packem_shared/ansi-parser-DlgLtOYO.js +0 -1
  177. package/dist/packem_shared/ansi-tokenizer-BU67A126.js +0 -1
  178. package/dist/packem_shared/buildCursorOnlySequence-CerkmjWt.js +0 -1
  179. package/dist/packem_shared/calculateScroll-D4Y_JR4H.js +0 -1
  180. package/dist/packem_shared/calculateScrollbarLayout-Lf6i24c9.js +0 -1
  181. package/dist/packem_shared/clearOsc52-BUpnQOav.js +0 -1
  182. package/dist/packem_shared/clearStringWidthCache-DKFjfJuB.js +0 -1
  183. package/dist/packem_shared/colorize-DU4YZkp3.js +0 -1
  184. package/dist/packem_shared/createBrailleGrid-BTOQrujS.js +0 -1
  185. package/dist/packem_shared/createCanvasBuffer-CL6sAM-A.js +0 -1
  186. package/dist/packem_shared/createInlineLoop-BMDYJkRp.js +0 -2
  187. package/dist/packem_shared/createScreen-DoYpyL0V.js +0 -3
  188. package/dist/packem_shared/cursor-context-CFviBqPX.js +0 -1
  189. package/dist/packem_shared/dom-rphpG0kf.js +0 -1
  190. package/dist/packem_shared/formatDuration-Bdx4ZgRh.js +0 -1
  191. package/dist/packem_shared/getPathToRoot-PDJeqiEH.js +0 -1
  192. package/dist/packem_shared/index-Dl9I2_QH.js +0 -75
  193. package/dist/packem_shared/isIntersecting-Bo2npvMR.js +0 -1
  194. package/dist/packem_shared/isTerminalPaletteQuerySupported-BYzmqq9-.js +0 -1
  195. package/dist/packem_shared/kittyFlags-g8ALyoCU.js +0 -1
  196. package/dist/packem_shared/load-native-root-binding-CxJnHcac.js +0 -1
  197. package/dist/packem_shared/measure-element-D4M9iSYp.js +0 -1
  198. package/dist/packem_shared/measure-text-B7juNq4Y.js +0 -3
  199. package/dist/packem_shared/mouse-context-DaARgUu1.js +0 -1
  200. package/dist/packem_shared/parseSgrMouse-bUrqPrh-.js +0 -1
  201. package/dist/packem_shared/processLayout-I83k6vXE.js +0 -2
  202. package/dist/packem_shared/reconciler-D4fi5NfR.js +0 -1
  203. package/dist/packem_shared/reconciler-DkwOtC5B.js +0 -1
  204. package/dist/packem_shared/render-CPVY5vpQ.js +0 -1
  205. package/dist/packem_shared/render-CvhjGwOg.js +0 -24
  206. package/dist/packem_shared/renderToString-B1LgWcJe.js +0 -4
  207. package/dist/packem_shared/renderToString-Df6HST7u.js +0 -2
  208. package/dist/packem_shared/renderToken-DjiQ6dfv.js +0 -1
  209. package/dist/packem_shared/renderTreeToBuffer-BpSD0sBJ.js +0 -2
  210. package/dist/packem_shared/renderer-Cs0KEr1o.js +0 -17
  211. package/dist/packem_shared/squashTextNodesWithMap-BmUSBPfc.js +0 -1
  212. package/dist/packem_shared/stderr-context-CR2LLec6.js +0 -1
  213. package/dist/packem_shared/stdin-context-BjMA9Sbi.js +0 -1
  214. package/dist/packem_shared/stdout-context-DAAlQct2.js +0 -1
  215. package/dist/packem_shared/terminal-palette.d-JbWHISW-.d.ts +0 -19
  216. package/dist/packem_shared/text-width-e49vlbQH.js +0 -2
  217. package/dist/packem_shared/utils-CVgM8kTn.js +0 -1
  218. package/dist/packem_shared/waitFor-CTAki32d.js +0 -4
  219. package/dist/packem_shared/wrapOrTruncateStyledLine-46W8bTtv.js +0 -3
@@ -1,10 +1,742 @@
1
1
  import { ReactNode, PropsWithChildren, RefAttributes, ForwardRefExoticComponent } from 'react';
2
- import { Except } from 'type-fest';
3
- import { D as DOMElement } from "../packem_shared/dom.d-CLGlidfI.js";
4
- import { S as Styles } from "../packem_shared/styles.d-CKGQFfm4.js";
2
+ import { D as DOMElement } from "../packem_shared/dom.d-BV2bnRcH.js";
3
+ import { S as Styles } from "../packem_shared/styles.d-BCZOPl_g.js";
5
4
  import 'yoga-layout';
6
5
  import "../ink/public/cursor.js";
7
6
  import '@visulima/colorize';
7
+ /**
8
+ Returns a boolean for whether the given type is `any`.
9
+
10
+ @link https://stackoverflow.com/a/49928360/1490091
11
+
12
+ Useful in type utilities, such as disallowing `any`s to be passed to a function.
13
+
14
+ @example
15
+ ```
16
+ import type {IsAny} from 'type-fest';
17
+
18
+ const typedObject = {a: 1, b: 2} as const;
19
+ const anyObject: any = {a: 1, b: 2};
20
+
21
+ function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
22
+ return object[key];
23
+ }
24
+
25
+ const typedA = get(typedObject, 'a');
26
+ //=> 1
27
+
28
+ const anyA = get(anyObject, 'a');
29
+ //=> any
30
+ ```
31
+
32
+ @category Type Guard
33
+ @category Utilities
34
+ */
35
+ type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
36
+ /**
37
+ Returns a boolean for whether the given key is an optional key of type.
38
+
39
+ This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
40
+
41
+ @example
42
+ ```
43
+ import type {IsOptionalKeyOf} from 'type-fest';
44
+
45
+ type User = {
46
+ name: string;
47
+ surname: string;
48
+
49
+ luckyNumber?: number;
50
+ };
51
+
52
+ type Admin = {
53
+ name: string;
54
+ surname?: string;
55
+ };
56
+
57
+ type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
58
+ //=> true
59
+
60
+ type T2 = IsOptionalKeyOf<User, 'name'>;
61
+ //=> false
62
+
63
+ type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
64
+ //=> boolean
65
+
66
+ type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
67
+ //=> false
68
+
69
+ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
70
+ //=> boolean
71
+ ```
72
+
73
+ @category Type Guard
74
+ @category Utilities
75
+ */
76
+ type IsOptionalKeyOf<Type extends object, Key extends keyof Type> = IsAny<Type | Key> extends true ? never : Key extends keyof Type ? Type extends Record<Key, Type[Key]> ? false : true : false;
77
+ /**
78
+ Extract all optional keys from the given type.
79
+
80
+ This is useful when you want to create a new type that contains different type values for the optional keys only.
81
+
82
+ @example
83
+ ```
84
+ import type {OptionalKeysOf, Except} from 'type-fest';
85
+
86
+ type User = {
87
+ name: string;
88
+ surname: string;
89
+
90
+ luckyNumber?: number;
91
+ };
92
+
93
+ const REMOVE_FIELD = Symbol('remove field symbol');
94
+ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
95
+ [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
96
+ };
97
+
98
+ const update1: UpdateOperation<User> = {
99
+ name: 'Alice',
100
+ };
101
+
102
+ const update2: UpdateOperation<User> = {
103
+ name: 'Bob',
104
+ luckyNumber: REMOVE_FIELD,
105
+ };
106
+ ```
107
+
108
+ @category Utilities
109
+ */
110
+ type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
111
+ ? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never; }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
112
+ : never; // Should never happen
113
+ /**
114
+ Extract all required keys from the given type.
115
+
116
+ This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
117
+
118
+ @example
119
+ ```
120
+ import type {RequiredKeysOf} from 'type-fest';
121
+
122
+ declare function createValidation<
123
+ Entity extends object,
124
+ Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
125
+ >(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
126
+
127
+ type User = {
128
+ name: string;
129
+ surname: string;
130
+ luckyNumber?: number;
131
+ };
132
+
133
+ const validator1 = createValidation<User>('name', value => value.length < 25);
134
+ const validator2 = createValidation<User>('surname', value => value.length < 25);
135
+
136
+ // @ts-expect-error
137
+ const validator3 = createValidation<User>('luckyNumber', value => value > 0);
138
+ // Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
139
+ ```
140
+
141
+ @category Utilities
142
+ */
143
+ type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
144
+ ? Exclude<keyof Type, OptionalKeysOf<Type>> : never; // Should never happen
145
+ /**
146
+ Returns a boolean for whether the given type is `never`.
147
+
148
+ @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
149
+ @link https://stackoverflow.com/a/53984913/10292952
150
+ @link https://www.zhenghao.io/posts/ts-never
151
+
152
+ Useful in type utilities, such as checking if something does not occur.
153
+
154
+ @example
155
+ ```
156
+ import type {IsNever, And} from 'type-fest';
157
+
158
+ type A = IsNever<never>;
159
+ //=> true
160
+
161
+ type B = IsNever<any>;
162
+ //=> false
163
+
164
+ type C = IsNever<unknown>;
165
+ //=> false
166
+
167
+ type D = IsNever<never[]>;
168
+ //=> false
169
+
170
+ type E = IsNever<object>;
171
+ //=> false
172
+
173
+ type F = IsNever<string>;
174
+ //=> false
175
+ ```
176
+
177
+ @example
178
+ ```
179
+ import type {IsNever} from 'type-fest';
180
+
181
+ type IsTrue<T> = T extends true ? true : false;
182
+
183
+ // When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
184
+ type A = IsTrue<never>;
185
+ //=> never
186
+
187
+ // If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
188
+ type IsTrueFixed<T> =
189
+ IsNever<T> extends true ? false : T extends true ? true : false;
190
+
191
+ type B = IsTrueFixed<never>;
192
+ //=> false
193
+ ```
194
+
195
+ @category Type Guard
196
+ @category Utilities
197
+ */
198
+ type IsNever<T> = [T] extends [never] ? true : false;
199
+ /**
200
+ An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
201
+
202
+ Use-cases:
203
+ - You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
204
+
205
+ Note:
206
+ - Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
207
+ - Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
208
+
209
+ @example
210
+ ```
211
+ import type {If} from 'type-fest';
212
+
213
+ type A = If<true, 'yes', 'no'>;
214
+ //=> 'yes'
215
+
216
+ type B = If<false, 'yes', 'no'>;
217
+ //=> 'no'
218
+
219
+ type C = If<boolean, 'yes', 'no'>;
220
+ //=> 'yes' | 'no'
221
+
222
+ type D = If<any, 'yes', 'no'>;
223
+ //=> 'yes' | 'no'
224
+
225
+ type E = If<never, 'yes', 'no'>;
226
+ //=> 'no'
227
+ ```
228
+
229
+ @example
230
+ ```
231
+ import type {If, IsAny, IsNever} from 'type-fest';
232
+
233
+ type A = If<IsAny<unknown>, 'is any', 'not any'>;
234
+ //=> 'not any'
235
+
236
+ type B = If<IsNever<never>, 'is never', 'not never'>;
237
+ //=> 'is never'
238
+ ```
239
+
240
+ @example
241
+ ```
242
+ import type {If, IsEqual} from 'type-fest';
243
+
244
+ type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
245
+
246
+ type A = IfEqual<string, string, 'equal', 'not equal'>;
247
+ //=> 'equal'
248
+
249
+ type B = IfEqual<string, number, 'equal', 'not equal'>;
250
+ //=> 'not equal'
251
+ ```
252
+
253
+ Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
254
+
255
+ @example
256
+ ```
257
+ import type {If, IsEqual, StringRepeat} from 'type-fest';
258
+
259
+ type HundredZeroes = StringRepeat<'0', 100>;
260
+
261
+ // The following implementation is not tail recursive
262
+ type Includes<S extends string, Char extends string> =
263
+ S extends `${infer First}${infer Rest}`
264
+ ? If<IsEqual<First, Char>,
265
+ 'found',
266
+ Includes<Rest, Char>>
267
+ : 'not found';
268
+
269
+ // Hence, instantiations with long strings will fail
270
+ // @ts-expect-error
271
+ type Fails = Includes<HundredZeroes, '1'>;
272
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
273
+ // Error: Type instantiation is excessively deep and possibly infinite.
274
+
275
+ // However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
276
+ type IncludesWithoutIf<S extends string, Char extends string> =
277
+ S extends `${infer First}${infer Rest}`
278
+ ? IsEqual<First, Char> extends true
279
+ ? 'found'
280
+ : IncludesWithoutIf<Rest, Char>
281
+ : 'not found';
282
+
283
+ // Now, instantiations with long strings will work
284
+ type Works = IncludesWithoutIf<HundredZeroes, '1'>;
285
+ //=> 'not found'
286
+ ```
287
+
288
+ @category Type Guard
289
+ @category Utilities
290
+ */
291
+ type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
292
+ /**
293
+ Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
294
+
295
+ @example
296
+ ```
297
+ import type {Simplify} from 'type-fest';
298
+
299
+ type PositionProps = {
300
+ top: number;
301
+ left: number;
302
+ };
303
+
304
+ type SizeProps = {
305
+ width: number;
306
+ height: number;
307
+ };
308
+
309
+ // In your editor, hovering over `Props` will show a flattened object with all the properties.
310
+ type Props = Simplify<PositionProps & SizeProps>;
311
+ ```
312
+
313
+ Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
314
+
315
+ If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
316
+
317
+ @example
318
+ ```
319
+ import type {Simplify} from 'type-fest';
320
+
321
+ interface SomeInterface {
322
+ foo: number;
323
+ bar?: string;
324
+ baz: number | undefined;
325
+ }
326
+
327
+ type SomeType = {
328
+ foo: number;
329
+ bar?: string;
330
+ baz: number | undefined;
331
+ };
332
+
333
+ const literal = {foo: 123, bar: 'hello', baz: 456};
334
+ const someType: SomeType = literal;
335
+ const someInterface: SomeInterface = literal;
336
+
337
+ declare function fn(object: Record<string, unknown>): void;
338
+
339
+ fn(literal); // Good: literal object type is sealed
340
+ fn(someType); // Good: type is sealed
341
+ // @ts-expect-error
342
+ fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
343
+ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
344
+ ```
345
+
346
+ @link https://github.com/microsoft/TypeScript/issues/15300
347
+ @see {@link SimplifyDeep}
348
+ @category Object
349
+ */
350
+ type Simplify<T> = { [KeyType in keyof T]: T[KeyType]; } & {};
351
+ /**
352
+ Returns a boolean for whether the two given types are equal.
353
+
354
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
355
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
356
+
357
+ Use-cases:
358
+ - If you want to make a conditional branch based on the result of a comparison of two types.
359
+
360
+ @example
361
+ ```
362
+ import type {IsEqual} from 'type-fest';
363
+
364
+ // This type returns a boolean for whether the given array includes the given item.
365
+ // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
366
+ type Includes<Value extends readonly any[], Item> =
367
+ Value extends readonly [Value[0], ...infer rest]
368
+ ? IsEqual<Value[0], Item> extends true
369
+ ? true
370
+ : Includes<rest, Item>
371
+ : false;
372
+ ```
373
+
374
+ @category Type Guard
375
+ @category Utilities
376
+ */
377
+ type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false : false;
378
+ // This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
379
+ type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
380
+ /**
381
+ Omit any index signatures from the given object type, leaving only explicitly defined properties.
382
+
383
+ This is the counterpart of `PickIndexSignature`.
384
+
385
+ Use-cases:
386
+ - Remove overly permissive signatures from third-party types.
387
+
388
+ This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
389
+
390
+ It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
391
+
392
+ (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
393
+
394
+ ```
395
+ const indexed: Record<string, unknown> = {}; // Allowed
396
+
397
+ // @ts-expect-error
398
+ const keyed: Record<'foo', unknown> = {}; // Error
399
+ // TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
400
+ ```
401
+
402
+ Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
403
+
404
+ ```
405
+ type Indexed = {} extends Record<string, unknown>
406
+ ? '✅ `{}` is assignable to `Record<string, unknown>`'
407
+ : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
408
+
409
+ type IndexedResult = Indexed;
410
+ //=> '✅ `{}` is assignable to `Record<string, unknown>`'
411
+
412
+ type Keyed = {} extends Record<'foo' | 'bar', unknown>
413
+ ? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
414
+ : '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
415
+
416
+ type KeyedResult = Keyed;
417
+ //=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
418
+ ```
419
+
420
+ Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
421
+
422
+ ```
423
+ type OmitIndexSignature<ObjectType> = {
424
+ [KeyType in keyof ObjectType // Map each key of `ObjectType`...
425
+ ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
426
+ };
427
+ ```
428
+
429
+ ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
430
+
431
+ ```
432
+ type OmitIndexSignature<ObjectType> = {
433
+ [KeyType in keyof ObjectType
434
+ // Is `{}` assignable to `Record<KeyType, unknown>`?
435
+ as {} extends Record<KeyType, unknown>
436
+ ? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
437
+ : KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
438
+ ]: ObjectType[KeyType];
439
+ };
440
+ ```
441
+
442
+ If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
443
+
444
+ @example
445
+ ```
446
+ import type {OmitIndexSignature} from 'type-fest';
447
+
448
+ type Example = {
449
+ // These index signatures will be removed.
450
+ [x: string]: any;
451
+ [x: number]: any;
452
+ [x: symbol]: any;
453
+ [x: `head-${string}`]: string;
454
+ [x: `${string}-tail`]: string;
455
+ [x: `head-${string}-tail`]: string;
456
+ [x: `${bigint}`]: string;
457
+ [x: `embedded-${number}`]: string;
458
+
459
+ // These explicitly defined keys will remain.
460
+ foo: 'bar';
461
+ qux?: 'baz';
462
+ };
463
+
464
+ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
465
+ //=> {foo: 'bar'; qux?: 'baz'}
466
+ ```
467
+
468
+ @see {@link PickIndexSignature}
469
+ @category Object
470
+ */
471
+ type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType]; };
472
+ /**
473
+ Pick only index signatures from the given object type, leaving out all explicitly defined properties.
474
+
475
+ This is the counterpart of `OmitIndexSignature`.
476
+
477
+ @example
478
+ ```
479
+ import type {PickIndexSignature} from 'type-fest';
480
+
481
+ declare const symbolKey: unique symbol;
482
+
483
+ type Example = {
484
+ // These index signatures will remain.
485
+ [x: string]: unknown;
486
+ [x: number]: unknown;
487
+ [x: symbol]: unknown;
488
+ [x: `head-${string}`]: string;
489
+ [x: `${string}-tail`]: string;
490
+ [x: `head-${string}-tail`]: string;
491
+ [x: `${bigint}`]: string;
492
+ [x: `embedded-${number}`]: string;
493
+
494
+ // These explicitly defined keys will be removed.
495
+ ['kebab-case-key']: string;
496
+ [symbolKey]: string;
497
+ foo: 'bar';
498
+ qux?: 'baz';
499
+ };
500
+
501
+ type ExampleIndexSignature = PickIndexSignature<Example>;
502
+ // {
503
+ // [x: string]: unknown;
504
+ // [x: number]: unknown;
505
+ // [x: symbol]: unknown;
506
+ // [x: `head-${string}`]: string;
507
+ // [x: `${string}-tail`]: string;
508
+ // [x: `head-${string}-tail`]: string;
509
+ // [x: `${bigint}`]: string;
510
+ // [x: `embedded-${number}`]: string;
511
+ // }
512
+ ```
513
+
514
+ @see {@link OmitIndexSignature}
515
+ @category Object
516
+ */
517
+ type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType]; };
518
+ // Merges two objects without worrying about index signatures.
519
+ type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key]; } & Source>;
520
+ /**
521
+ Merge two types into a new type. Keys of the second type overrides keys of the first type.
522
+
523
+ This is different from the TypeScript `&` (intersection) operator. With `&`, conflicting property types are intersected, which often results in `never`. For example, `{a: string} & {a: number}` makes `a` become `string & number`, which resolves to `never`. With `Merge`, the second type's keys cleanly override the first, so `Merge<{a: string}, {a: number}>` gives `{a: number}` as expected. `Merge` also produces a flattened type (via `Simplify`), making it more readable in IDE tooltips compared to `A & B`.
524
+
525
+ @example
526
+ ```
527
+ import type {Merge} from 'type-fest';
528
+
529
+ type Foo = {
530
+ a: string;
531
+ b: number;
532
+ };
533
+
534
+ type Bar = {
535
+ a: number; // Conflicts with Foo['a']
536
+ c: boolean;
537
+ };
538
+
539
+ // With `&`, `a` becomes `string & number` which is `never`. Not what you want.
540
+ type WithIntersection = (Foo & Bar)['a'];
541
+ //=> never
542
+
543
+ // With `Merge`, `a` is cleanly overridden to `number`.
544
+ type WithMerge = Merge<Foo, Bar>['a'];
545
+ //=> number
546
+ ```
547
+
548
+ @example
549
+ ```
550
+ import type {Merge} from 'type-fest';
551
+
552
+ type Foo = {
553
+ [x: string]: unknown;
554
+ [x: number]: unknown;
555
+ foo: string;
556
+ bar: symbol;
557
+ };
558
+
559
+ type Bar = {
560
+ [x: number]: number;
561
+ [x: symbol]: unknown;
562
+ bar: Date;
563
+ baz: boolean;
564
+ };
565
+
566
+ export type FooBar = Merge<Foo, Bar>;
567
+ //=> {
568
+ // [x: string]: unknown;
569
+ // [x: number]: number;
570
+ // [x: symbol]: unknown;
571
+ // foo: string;
572
+ // bar: Date;
573
+ // baz: boolean;
574
+ // }
575
+ ```
576
+
577
+ Note: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.
578
+
579
+ @see {@link ObjectMerge}
580
+ @category Object
581
+ */
582
+ type Merge<Destination, Source> = Destination extends unknown // For distributing `Destination`
583
+ ? Source extends unknown // For distributing `Source`
584
+ ? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>> : never // Should never happen
585
+ : never; // Should never happen
586
+ type _Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
587
+ /**
588
+ Merges user specified options with default options.
589
+
590
+ @example
591
+ ```
592
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
593
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
594
+ type SpecifiedOptions = {leavesOnly: true};
595
+
596
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
597
+ //=> {maxRecursionDepth: 10; leavesOnly: true}
598
+ ```
599
+
600
+ @example
601
+ ```
602
+ // Complains if default values are not provided for optional options
603
+
604
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
605
+ type DefaultPathsOptions = {maxRecursionDepth: 10};
606
+ type SpecifiedOptions = {};
607
+
608
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
609
+ // ~~~~~~~~~~~~~~~~~~~
610
+ // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
611
+ ```
612
+
613
+ @example
614
+ ```
615
+ // Complains if an option's default type does not conform to the expected type
616
+
617
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
618
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
619
+ type SpecifiedOptions = {};
620
+
621
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
622
+ // ~~~~~~~~~~~~~~~~~~~
623
+ // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
624
+ ```
625
+
626
+ @example
627
+ ```
628
+ // Complains if an option's specified type does not conform to the expected type
629
+
630
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
631
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
632
+ type SpecifiedOptions = {leavesOnly: 'yes'};
633
+
634
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
635
+ // ~~~~~~~~~~~~~~~~
636
+ // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
637
+ ```
638
+ */
639
+ type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = _ApplyDefaultOptions<Options, Defaults, SpecifiedOptions> extends (infer Result extends Required<Options> // `extends Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
640
+ ) ? Result : never;
641
+ type _ApplyDefaultOptions<Options, Defaults, SpecifiedOptions> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Merge<Defaults, { [Key in keyof SpecifiedOptions as undefined extends Required<Options>[Key & keyof Options] ? Key : undefined extends SpecifiedOptions[Key] ? never : Key]: SpecifiedOptions[Key]; }>>>;
642
+ /**
643
+ Filter out keys from an object.
644
+
645
+ Returns `never` if `Exclude` is strictly equal to `Key`.
646
+ Returns `never` if `Key` extends `Exclude`.
647
+ Returns `Key` otherwise.
648
+
649
+ @example
650
+ ```
651
+ type Filtered = Filter<'foo', 'foo'>;
652
+ //=> never
653
+ ```
654
+
655
+ @example
656
+ ```
657
+ type Filtered = Filter<'bar', string>;
658
+ //=> never
659
+ ```
660
+
661
+ @example
662
+ ```
663
+ type Filtered = Filter<'bar', 'foo'>;
664
+ //=> 'bar'
665
+ ```
666
+
667
+ @see {Except}
668
+ */
669
+ type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
670
+ type ExceptOptions = {
671
+ /**
672
+ Disallow assigning non-specified properties.
673
+
674
+ Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
675
+
676
+ @default false
677
+ */
678
+ requireExactProps?: boolean;
679
+ };
680
+ type DefaultExceptOptions = {
681
+ requireExactProps: false;
682
+ };
683
+ /**
684
+ Create a type from an object type without certain keys.
685
+
686
+ We recommend setting the `requireExactProps` option to `true`.
687
+
688
+ This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
689
+
690
+ This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
691
+
692
+ @example
693
+ ```
694
+ import type {Except} from 'type-fest';
695
+
696
+ type Foo = {
697
+ a: number;
698
+ b: string;
699
+ };
700
+
701
+ type FooWithoutA = Except<Foo, 'a'>;
702
+ //=> {b: string}
703
+
704
+ // @ts-expect-error
705
+ const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
706
+ // errors: 'a' does not exist in type '{ b: string; }'
707
+
708
+ type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
709
+ //=> {a: number} & Partial<Record<'b', never>>
710
+
711
+ // @ts-expect-error
712
+ const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
713
+ // errors at 'b': Type 'string' is not assignable to type 'undefined'.
714
+
715
+ // The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
716
+
717
+ // Consider the following example:
718
+
719
+ type UserData = {
720
+ [metadata: string]: string;
721
+ email: string;
722
+ name: string;
723
+ role: 'admin' | 'user';
724
+ };
725
+
726
+ // `Omit` clearly doesn't behave as expected in this case:
727
+ type PostPayload = Omit<UserData, 'email'>;
728
+ //=> {[x: string]: string; [x: number]: string}
729
+
730
+ // In situations like this, `Except` works better.
731
+ // It simply removes the `email` key while preserving all the other keys.
732
+ type PostPayloadFixed = Except<UserData, 'email'>;
733
+ //=> {[x: string]: string; name: string; role: 'admin' | 'user'}
734
+ ```
735
+
736
+ @category Object
737
+ */
738
+ type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
739
+ type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType]; } & (Options['requireExactProps'] extends true ? Partial<Record<KeysType, never>> : {});
8
740
  type Props = Except<Styles, "textWrap"> & {
9
741
  /**
10
742
  * Hide the element from screen readers.