I'm trying to convert a project to TypeScript, and I have most things set up, but I'm still struggling with getting the last few pieces put together. I want to be able to use this TypesScript project from a normal JavaScript project, so my understanding is that I need to emit d.ts files for my existing sources. My sources are all .js currently and we plan to slowly migrate to TS over time. My issue is getting the declarations to emit with the current exports/require statements.
A simple demonstration of the issue:
mod1.js
class MyClass {
constructor(name) {
this.name = name;
}
}
module.exports = {
MyClass,
};
mod2.js
const mod1 = require('./mod1');
module.exports = {
MyClass: mod1.MyClass,
};
As soon as I try to export MyClass in mod2 in order to re-route the namespace one can access MyClass from when consuming the project, I get Declaration emit for this file requires using private name 'MyClass' from module '"mod1"'. An explicit type annotation may unblock declaration emit.ts(9006)
We have a lot of re-routes in our code base, groups of files that hold various classes, and then we use index.js files at each dir level to define which items are available in that namespace, and sometimes a bunch of UI elements which are instantiated class instances so we can make calls such as:
const {app, appui} = require('our-cool-app');
app.feature1.doSomething();
appui.component.someButton.click();
Is there an easy fix to get our d.ts files auto generated from the .js sources?