We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1d6c25c commit 303d480Copy full SHA for 303d480
server/src/util/discriminate.ts
@@ -0,0 +1,8 @@
1
+export function discriminate<K extends PropertyKey, V extends string | number | boolean>(
2
+ discriminantKey: K,
3
+ discriminantValue: V,
4
+) {
5
+ return <T extends Record<K, any>>(
6
+ obj: T & Record<K, V extends T[K] ? T[K] : V>,
7
+ ): obj is Extract<T, Record<K, V>> => obj[discriminantKey] === discriminantValue
8
+}
0 commit comments