summaryrefslogtreecommitdiff
path: root/src/utils/types.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/types.ts')
-rw-r--r--src/utils/types.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/utils/types.ts b/src/utils/types.ts
new file mode 100644
index 0000000..4cb85aa
--- /dev/null
+++ b/src/utils/types.ts
@@ -0,0 +1,17 @@
+/**
+ * Determine if {@linkcode input} matches the `"object"` type
+ */
+export function isObject(input: unknown): input is object {
+ return typeof input === 'object' && !!input;
+}
+
+type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
+
+/**
+ * Helper type for creating an exclusive union between two types
+ *
+ * @see {@link https://stackoverflow.com/a/53229567/2250435 | StackOverflow Post}
+ */
+export type XOR<T, U> = T | U extends object
+ ? (Without<T, U> & U) | (Without<U, T> & T)
+ : T | U;