Currently I am in the process of developing a private npm package for internal use. One challenge I am facing is how to include flowtypes that can be shared across different internal projects. Ideally, I would like these flowtypes to be imported in the format
import type {SomeType} from 'our-private-lib'
. What approach should I take to successfully include flow types with my npm package?
As of now, I have been transpiling all ES code using babel and utilizing flow-copy-source
to copy original files alongside the transpiled ones, but with a .js.flow
extension. This method, however, requires the names of these files to match the transpiled counterparts.
For instance, if I have a file located at /super-schema/index.js
containing:
export type SuperSchemaType = {
prop1: boolean,
prop2: string
}
const SuperSchema = {
prop1: true,
prop2: 'Hello'
}
module.exports = SuperSchema;
And my package.json references the main file as index.js
, which exports SuperSchema
as follows:
module.exports = {
superSchema: require('./super-schema.js/index.js');
}
I could then import this module like so:
import {superSchema} from 'our-private-lib';
However, integrating flowtype raises complications. The syntax
import type {SuperSchemaType} from 'our-private-lib';
does not seem to function as expected. Any suggestions on how to address this issue?