Created
July 19, 2016 02:43
-
-
Save shanecav/796fa6e4b93ee0ffcd882b039090627c to your computer and use it in GitHub Desktop.
Flowtype error on node http Server listen method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createServer = require('http').createServer | |
const app = require('./http/app') // Express app | |
const server = createServer(app) | |
server.listen(port) | |
/** | |
* ^ This is where I'm getting the Flow error: | |
* | |
* call of method `listen`: /Users/shane/projects/blockpop/server/src/server.js:22 | |
* Function cannot be called on any member of intersection type | |
* intersection: /Users/shane/projects/blockpop/server/src/server.js:22 | |
* Member 1: | |
* function type: /private/tmp/flow/flowlib_3f09764c/node.js:696 | |
* Error: | |
* boolean: /Users/shane/projects/blockpop/server/src/server.js:22 | |
* This type is incompatible with | |
* number: /private/tmp/flow/flowlib_3f09764c/node.js:696 | |
* Member 2: | |
* function type: /private/tmp/flow/flowlib_3f09764c/node.js:697 | |
* Error: | |
* boolean: /Users/shane/projects/blockpop/server/src/server.js:22 | |
* This type is incompatible with | |
* string: /private/tmp/flow/flowlib_3f09764c/node.js:697 | |
* Member 3: | |
* function type: /private/tmp/flow/flowlib_3f09764c/node.js:698 | |
* Error: | |
* boolean: /Users/shane/projects/blockpop/server/src/server.js:22 | |
* This type is incompatible with | |
* object type: /private/tmp/flow/flowlib_3f09764c/node.js:698 | |
*/ | |
// Here's the http declaration Flow is using, which is referenced in the Flow error above: | |
declare module "http" { | |
declare class Server extends net$Server { | |
listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; // line 696 | |
listen(path: string, callback?: Function): Server; // line 697 | |
listen(handle: Object, callback?: Function): Server; // line 698 | |
close(callback?: Function): Server; | |
maxHeadersCount: number; | |
setTimeout(msecs: number, callback: Function): Server; | |
timeout: number; | |
} | |
declare class ClientRequest extends http$ClientRequest {} | |
declare class IncomingMessage extends http$IncomingMessage {} | |
declare function createServer(listener?: Function): Server; | |
declare function request( | |
options: Object | string, | |
callback?: (response: IncomingMessage) => void | |
): ClientRequest; | |
declare function get( | |
options: Object | string, | |
callback?: (response: IncomingMessage) => void | |
): ClientRequest; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Flow is inferring the type of
port
to beboolean
. The error shows that there are 3 possible ways to calllisten
, one that takes anumber
, one astring
, and one anObject
—andboolean
is incompatible with all of those.