facebook/flow

Can't get flow type coverage for a function

Open

#2.255 aberto em 16 de ago. de 2016

Ver no GitHub
 (18 comments) (3 reactions) (0 assignees)Rust (1.885 forks)batch import
coveragehelp wanted

Métricas do repositório

Stars
 (22.203 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

I have the following function:

type KeyboardInfo = {
  key?: string,
  code?: string,
  meta?: boolean,
  alt?: boolean,
  ctrl?: boolean,
  shift?: boolean,
  prevent?: boolean,
  log?: boolean
}

function on(event: KeyboardEventTypes, {key, meta, alt, code, shift, ctrl, prevent = true, log = false}: KeyboardInfo, callback: (e: KeyboardEvent) => void) {
  window.addEventListener(event, (e: KeyboardEvent) => {
    if (log) {
      console.log(e);
    }

    if (key && e.key !== key) {
      return;
    }
    if (meta && e.metaKey !== meta) {
      return;
    }
    if (code && e.code !== code) {
      return;
    }
    if (ctrl && e.ctrlKey !== ctrl) {
      return;
    }
    if (alt && e.altKey !== alt) {
      return;
    }
    if (shift && e.shiftKey !== shift) {
      return;
    }
    if (prevent) {
      e.preventDefault();
    }
    callback(e);
  });
}

I try to get this covered by flow, but I'm not sure how. Atom says it is not covered: image

Is this because I call window? Not sure what is going on here.

Guia do colaborador