declare function havoc(): void;

function test_member() {
  declare const x: { m?: (cb: (n: number) => void) => void };

  x.m && x.m(u => { u as string; }); // error number ~> string

  if (x.m) {
    havoc();
    x.m(u => { u as string; });  // error: undefined not a function & mising local annotation
  }

  if (x.m) {
    x.m(u => { u as number; }); // ok
  }

  if (x.m) {
    x.m(u => { u as string; }); // error number ~> string
  }
}

function test_optional_member() {
  declare const x: ?{ m?: (cb: (n: number) => void) => void };

  x?.m && x?.m(u => { u as string; }); // error number ~> string

  if (x?.m) {
    havoc();
    x?.m(u => { u as string; });  // error: undefined not a function & mising local annotation
  }

  if (x?.m) {
    x?.m(u => { u as number; }); // ok
  }

  if (x?.m) {
    x?.m(u => { u as string; }); // error number ~> string
  }
}
