function a(x: X) { // AdderT x + x as X; // nope x + x as number; // UnaryMinusT -x as X; // nope -x as number; // AssertArithOperandT x * x as X; x * x as number; // coercion `blah ${x}` as string; } function b(x: X, y: Y) { //EqT, StrictEqT, CompartatorT (x == x) as boolean; (x === x) as boolean; (x == y) as boolean; // nope (x === y) as boolean; // nope, constant-condition error (x < x) as boolean; (x < y) as boolean; // nope } function c>( s: S, x: X, y: Y, ) { // AssertForInRHST for (const _ in x) { } // AssertBinaryIn[L|R]HST s in x; 42 in y; } // MatchingPropT function e(x: X) { if (x.a === 'T') { } } //TestPropT function f(x: Array) { if (x[0] != null && x[0].id === 'a') { // This seems questionable but models current behavior for mixed } } function h(x: X): {[_K in keyof X]: string} { return ['a']; // error, mapped type doesn't have the unsoundness issue } // ToStringT function gn(jsEnum: {[key: TType]: string, ...}) { Object.keys(jsEnum) as ReadonlyArray; } // KeysT function gv< TFormData extends {...}, TValidators extends {[K in keyof TFormData]: number}, >( data: TFormData, validators: TValidators, ): {[K in keyof TFormData]: ?string} { return Object.keys(data).reduce( // error: cannot satisfy generic mapped type (acc: {[K in keyof TFormData]: ?string}, k: K): {[K in keyof TFormData]: ?string} => // $FlowExpectedError[unsafe-object-assign] Object.assign(acc, {[k]: validators[k](k, data)}), {}, ); } // More KeysT function kt(fieldName: TKey): void { if (fieldName) { return; } } // OptionalChain.run function oc< T extends Readonly<{id: ?string, ...}>, L extends ?Readonly<{ id: ?string, nextOneOne: ?{...}, ... }>, >( conversations: ReadonlyArray, lookup: {[key: string]: L, ...}, ): ReadonlyArray { return conversations.filter(conversation => { const {id} = conversation; if (id == null) { return false; } return lookup[id]?.nextOneOne == null; }); } // generic of key of generic const cc = () => (key: K, data: D) => { const [click, view] = data[key]; }; // generic refined to empty type ObjectKey = string | number; type ObjectType = {[key: TK]: TV, ...}; function ObjectFlip( obj: ObjectType, key: TK, ): {[key: string | number]: TK} { const flipped: {[key: string | number]: TK} = {}; const value: ?TV = obj[key]; if (value !== null && value !== undefined) { flipped[value] = key; } return flipped; } // Type Destructor type LLETT = | {response: {account: {activities: number, ...}, ...}, ...} | {response: {account: {...}, ...}, ...}; type LLETR = LLETT['response']; const elementType = (data: T): T['account'] => data.account; const directAccount = (data: T, otherData: LLETR): Readonly => otherData; type t = {a: number, ...} | {v: string, ...}; class C { _config: TConfig; __updateConfig(updater: (config: Readonly) => TConfig) { const config = updater(this._config); } } // Keys function gejses( key: keyof {[key: TMapKey]: $FlowFixMe, ...}, ): null { if (key) { } return null; } // Partial function partial_test(p: Partial): T { return p; // error } // A polymorphic bound is not instantiated when a hook makes its argument read-only type PolyFn = (value: Array) => void; hook useNarrowedPolyBound(f: T): T { return f; // ok }