Skip to content

Instantly share code, notes, and snippets.

@jeswin
Created February 29, 2016 12:37
Show Gist options
  • Save jeswin/22ccd02270589c360870 to your computer and use it in GitHub Desktop.
Save jeswin/22ccd02270589c360870 to your computer and use it in GitHub Desktop.

As in the following example, I am defining the return type of createServer() to be a MockServer interface (which is empty), instead of "Server" as defined in https://github.com/facebook/flow/blob/master/lib/node.js

Shouldn't this work, since an empty interface can stand in for any class?

/* @flow */
var http = require("http");

interface MockServer {}

type HttpModule = {
  createServer: (listener?: Function) => MockServer
}

function test(mod: HttpModule) {
  var p  = mod.createServer();
}

test(http);

The result of "flow check" is:

test.js:7
  7:   createServer: (listener?: Function) => MockServer
                                              ^^^^^^^^^^ MockServer. This type is incompatible with
689:   declare function createServer(listener?: Function): Server;
                                                           ^^^^^^ Server. See: /tmp/flow/flowl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment