Last active
March 10, 2018 12:42
-
-
Save ktsn/c8ff4416e0aae0488569827cf4ca97ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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