Last active
August 3, 2021 15:40
-
-
Save jacksteamdev/4de9c82fe789cf489458e93df453b446 to your computer and use it in GitHub Desktop.
TypeScript helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { copyStream } from '../common/messages' | |
type Unarray<T> = T extends Array<infer R> ? R : T; | |
type Unobservable<T> = T extends Observable<infer R> ? R : T; | |
type Unpacked<T> = T extends Array<infer R> ? R : T extends Observable<infer R> ? R : never; | |
type CopyData = Unobservable<typeof copyStream> | |
type BackgroundEvent = | |
| { type: 'copy'; data: CopyData } | |
| { type: 'xstate.done.performCopy'; data: { tabId: string } } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function not<Predicate extends (...args: any[]) => boolean>( | |
fn: Predicate | |
): Predicate { | |
// @ts-expect-error We're forwarding the args and negating the result | |
return (...args: Parameters<Predicate>) => !fn(...args) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment