I'm developing a node.js plugin in TypeScript.
The requirements are to export it as module.exports
directly, e.g. when compiled, the index.js
should look like this:
module.exports = require('./src/plugin.js').default;
My plugin.ts
looks like this:
import {Options} from './types';
export default function myPlugin(options?: Partial<Options>): any {
// ...
}
I can achieve the desired result by writing my index.ts
like this:
import myPlugin from './src/plugin';
export = myPlugin;
However, if I do this, the Options
type would not be exported in type definitions.
And, it's not possible to use export = module
construct with another exports for types.
I want the consumer to be able to import both the plugin function and the types for it:
import myPlugin = require('@acme/my-plugin');
import {Options} from '@acme/my-plugin';
Is it possible for the consumer to be able to import types from my module as well as it's main symbol?