Skip to content

Instantly share code, notes, and snippets.

View hasparus's full-sized avatar

Piotr Monwid-Olechnowicz hasparus

View GitHub Profile
type Defined<T extends object> = { [K in keyof T]: Exclude<T[K], undefined> };
type Assign<T1, T2> = {
[K in keyof T1 | keyof T2]: K extends keyof T2
? T2[K] extends undefined
? K extends keyof T1
? T1[K]
: never
: T2[K]
: K extends keyof T1
const questions = [
{
message: 'Enter your login (email address)...',
name: 'login',
type: 'input',
},
{
message: 'Enter your password...',
name: 'password',
type: 'password',
@hasparus
hasparus / typescript-merged-product.ts
Created July 16, 2019 14:29
I'm sure it has no serious use case.
namespace Products {
export type Car = {
name: 'Car';
drive(): void;
}
export type IceCream = {
name: 'IceCream';
flavor: string;
}
@hasparus
hasparus / tic-tac-toe.svelte
Last active August 3, 2019 21:27
I guess this is not really reactive and "svelte-way" but I had fun ¯\_(ツ)_/¯
// https://svelte.dev/repl/65dc3ff369ea423f918e7ac3425b5677?version=3.6.9
<script>
const pipe = (x, ...fs) => fs.reduce((v, f) => f(v), x);
const zip = xs => ys => xs.map((x, i) => [x, ys[i]]);
const head = xs => xs[0];
const filter = predicate => xs => xs.filter(predicate);
const map = predicate => xs => xs.map(predicate);
const tap = proc => x => {
proc(x);
function exhaustive(x: never): never {
throw new Error(`
Unreachable default case.
${x} is not assignable to type never.
`)
}
type Fruit = "apple" | "banana" | "mango";
declare const fruit: Fruit;
type Fluent<T extends object> = {
[K in keyof T]: (() => void) extends T[K]
? T[K] extends (...args: infer Params) => void
? (...args: Params) => Fluent<T>
: T[K]
: T[K];
};
/**
import * as t from "io-ts";
import { record } from "fp-ts/lib/Record";
const handler = <I, A, R>(decoder: t.Decoder<I, A>, f: (_: A) => R) => ({
decoder,
f,
});
type Handler = ReturnType<typeof handler>;