Created
April 26, 2017 05:02
-
-
Save dherman/95b84636c4b6e1903c999a1496dc2c77 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type NumberDict = {[key: string]: number}; | |
type NullableObject = {} | null; | |
function nullableObjectIsNumberDict(x: NullableObject): x is NumberDict { | |
return !!x && Object.keys(x).every(key => typeof x[key] === 'number'); | |
} | |
function use(x: NullableObject) { | |
if (!nullableObjectIsNumberDict(x)) { | |
return; | |
} | |
x // I expected NumberDict; TS says {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment