Becky
Becky

Reputation: 348

What is the correct way to import a native node module when using flow?

I have flow set up correctly, and it's working for most of my code (using React with all of the type definitions imported using flow-typed), however I am having trouble getting flow to cover this small file which imports a native node module (events):

import { EventEmitter } from 'events';

const eventBus: events.EventEmitter = new EventEmitter();
export default eventBus;

Flow is saying that line 3 const eventBus... is not covered by flow, flagging that new EventEmitter() is the issue. I thought that by specifying the type eventBus: events.EventEmitter that would solve the issue, but that seems to not be the case.

Is there something obviously wrong I am doing here?

Upvotes: 2

Views: 238

Answers (1)

Becky
Becky

Reputation: 348

Sillyness on my behalf (typically only realised as soon as I asked the question), the issue was nothing to do with flow, but the first import was incorrect. It should be import EventEmitter from 'events' and the type would then be eventBus: EventEmitter

Upvotes: 1

Related Questions