Skip to content

Instantly share code, notes, and snippets.

@ktsn
Last active March 10, 2018 12:42
Show Gist options
  • Save ktsn/c8ff4416e0aae0488569827cf4ca97ca to your computer and use it in GitHub Desktop.
Save ktsn/c8ff4416e0aae0488569827cf4ca97ca to your computer and use it in GitHub Desktop.
interface Mapping<K, V> {
_k: K;
_v: V;
}
type P<K, M extends Mapping<K, any>> = M extends Mapping<K, infer V>
? V
: never;
interface XMap<T extends Mapping<any, any> = Mapping<never, undefined>> {
set<K, V>(key: K, val: V): XMap<T | Mapping<K, V>>;
get<K>(key: K): P<K, T> | undefined;
}
declare const map: XMap;
const a = map.set("foo", 123);
const b = a.set(456, true);
const num = b.get("foo");
const bool = b.get(456);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment