Represent maps
// rather than
const map: {[ key: string ]: string} = {
foo: 'bar',
}
import { transformWhereInput } from './transformWhereInput' | |
test('basic', () => { | |
expect( | |
transformWhereInput({ | |
status: 'ACTIVE', | |
}), | |
).toEqual({ | |
status: { | |
$eq: 'ACTIVE', |
type AnyFunction = (...args: any) => any | |
type FunctionWithOneArg<T extends AnyFunction> = (args: Record<string, any>) => ReturnType<T> | |
type Without<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> | |
type Arguments<T> = [T] extends [(...args: infer U) => any] | |
? U | |
: [T] extends [void] ? [] : [T] | |
type PartialArg<T> = Partial<Arguments<T>[0]> |
import { cleanEnv, str, num, url } from 'envalid' | |
const env = cleanEnv(process.env, { | |
GRAPHQL_URL: url({ | |
devDefault: 'http://localhost:4000/graphql', | |
}), | |
PORT: num({ | |
devDefault: 3000, | |
}), | |
A: str(), |
import { someThing } from './someThing'; | |
console.log(someThing); // <-- Here you just just need to start typing `some..` in VSCode and it'll do the import automatically |
type Maybe<T> = T | null | undefined | |
function defaultValue<T>(value: Maybe<T>, fallback: T): T { | |
return value ?? fallback | |
} |
// gitignore this file | |
module.exports = { | |
HASURA_URL: 'https://myapp.herokuapp.com/v1/graphql', | |
HASURA_ADMIN_SECRET: 'xxx', | |
}; |
import { useEffect, useState, useRef } from 'react'; | |
import Talk from 'talkjs'; | |
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; | |
export type TalkJSState = | |
| { | |
status: 'error'; | |
error: Error; | |
session: null; | |
} |
// Next.js' `_app.js` file | |
import Head from 'next/head'; | |
import { useEffect, useState } from 'react'; | |
import '../styles/main.scss'; | |
function useIsMounted() { | |
const [mounted, setMounted] = useState(false); | |
useEffect(() => { |
// https://github.com/apollographql/react-apollo/issues/3735#issuecomment-562915341 | |
import ApolloClient, { ApolloError } from 'apollo-client'; | |
import { DocumentNode } from 'graphql'; | |
import { useEffect, useState } from 'react'; | |
import { useApolloClient } from '@apollo/react-hooks'; | |
export interface HookOptions<TData extends object, TVariables> { | |
variables?: TVariables; | |
mergeIntoCache?: ( |