Skip to content

Instantly share code, notes, and snippets.

@jacksteamdev
Last active August 3, 2021 15:40
Show Gist options
  • Save jacksteamdev/4de9c82fe789cf489458e93df453b446 to your computer and use it in GitHub Desktop.
Save jacksteamdev/4de9c82fe789cf489458e93df453b446 to your computer and use it in GitHub Desktop.
TypeScript helpers
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 } }
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