Skip to content

Instantly share code, notes, and snippets.

@dherman
Created April 26, 2017 05:02
Show Gist options
  • Save dherman/95b84636c4b6e1903c999a1496dc2c77 to your computer and use it in GitHub Desktop.
Save dherman/95b84636c4b6e1903c999a1496dc2c77 to your computer and use it in GitHub Desktop.
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