1

So I'm trying to refactor the type-declaration of a module called inquirer which is strictly namespace-structured.

I really don't like having one single file with 1k lines of code inside of it, so I tried to split the whole type-declaration up into multiple files and got lots of trouble doing so.

General

As I mentioned I'm writing type-declarations for a module called inquirer which is not working with es6-modules.

For example the exported member itself is an object of type PromptModule and a namespace with some classes and interfaces at the same time:

import inquirer = require("inquirer");
let question: inquirer.Question = { /* This is a question */ };
inquirer.prompt(question);
inquirer.restoreDefaultPrompts();
inquirer.registerPrompt({ /* this is a prompt */ });
let x = new inquirer.ui.Prompt();

Sadly I really couldn't find a way to split the inquirer-module up into separate files for each interface and/or class.

The only way I found was to perform a namespace-merge which is nicely described in a comment of @Ryan Cavanaugh right below the "Version 2"-heading.

Sadly I could not export the merged namespace in my index.d.ts-file.

This leads me to my question:

  • Is there even a way to reach this goal?
  • How can I wrap up the inquirer-module into a nice-to-maintain type-declaration?
manuth
  • 51
  • 5

0 Answers0