In a Flowtype interface declaration file, how do I declare a module's module.exports?
Say, for example, I am using Express:
import express from 'express';
const app = express();
The current syntax for this is
declare module express {
declare type Express { ...#use(), #post(), #get(), etc... }
declare var exports: () => Express
}
You can also use declare function exports(): Express, or use any other type you want, for example:
declare module moduleThatExportsNumber {
declare var exports: number
}
In the future this Common JS-based syntax may be replaced by something that reflects the semantics of ES6 modules.
In .js.flow files inside your own library, you can do:
declare function createExpress(): Express;
declare module.exports: typeof createExpress;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With