/* @flow */ function testKeysOfObject(str: string, lit: 'hi') { (str: $Keys); // Any string should be fine if (str) { (str: $Keys); // No error, truthy string should be fine } ('hi': $Keys); // String literal should be fine (123: $Keys); // Error: number -> keys of Object } type StrDict = {[key: string]: mixed}; function testKeysOfStrDict(str: string, lit: 'hi') { (str: $Keys); // Any string should be fine if (str) { (str: $Keys); // No error, truthy string should be fine } ('hi': $Keys); // String literal should be fine (123: $Keys); // Error: number -> keys of StrDict } type StrLitDict = {[key: 'hi']: mixed}; function testKeysOfStrLitDict(str: string, lit: 'hi') { (str: $Keys); // Error: Not all strings are allowed if (str) { (str: $Keys); // Error: Not all truthy strings are allowed } ('hi': $Keys); // The right string literal is allowed ('bye': $Keys); // Error: The wrong string literal is not allowed (123: $Keys); // Error: number -> keys of StrLitDict } type ObjLit = {hi: mixed}; function testKeysOfOtherObj(str: string, lit: 'hi') { (str: $Keys); // Error: string -> keys of ObjLit if (str) { (str: $Keys); // Error: truthy string -> keys of ObjLit } ('hi': $Keys); // String literal should be fine (123: $Keys); // Error: number -> keys of ObjLit }