This library is designed to solve the problem of transferring TypeScript type declarations between third-party javascript modules and improve the quality of TypeScript development.
For example, you can easily apply this solution for microfronted architecture built in any way.
For the latest stable version:
npm install -D ts-remote
import { compiler, type ModuleList } from 'ts-remote/compiler';
import path from 'path';
const moduleList: ModuleList = {
'moduleName': `./app/index.ts`,
'foo': `./app/foo.ts`,
'bar': `./app/bar.ts`,
// ...others
};
compiler({
output: {
filename: path.resolve(process.cwd(), '@types-remote-dist', 'moduleName.d.ts'),
format: (result) => {
const prettier = require('prettier');
return prettier.format(result);
},
},
moduleList,
additionalDeclarations: [`./app/global.d.ts`,],
});
--> moduleName.d.ts
declare module "moduleName" {
type A = number
const a: A
}
declare module "foo" {
// ..exports from module foo..
}
declare module "bar" {
// ..exports from module foo..
}
import { loader } from 'ts-remote/loader';
loader({
moduleList: { 'https://example.com/types/modeuleName.d.ts': '@types-remote-loaded/remote.d.ts' },
});
In the near future, it is planned to expand the functionality and use more TypeScript features.