Skip to content

Instantly share code, notes, and snippets.

@hediet hediet/main.ts

Created Apr 21, 2017
What would you like to do?
Acceptor / User Pattern for TypeScript
interface Acceptor<T extends string> {
accept(x: UserOf<T>): any;
allow<T1 extends string>(x: T1): Acceptor<T|T1>;
interface UserOf<T extends string> {
_brand: T;
function use<T extends string>(name: T): UserOf<T> { return null!; }
function combine<T1 extends string, T2 extends string>(x: UserOf<T1>, y: UserOf<T2>): UserOf<T1|T2> { return null!; }
const a = use("a");
const b = use("b");
const ab = combine(a, b);
let f: Acceptor<never> = null!;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.