Skip to content

TheMontanyes/ts-remote

Repository files navigation

ts-remote v1.1.1

npm version

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.

Installing

For the latest stable version:

npm install -D ts-remote

Usage

DTS module compiler

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`,],
});

Example output

--> 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..
}

Remote type loader

import { loader } from 'ts-remote/loader';

loader({
  moduleList: { 'https://example.com/types/modeuleName.d.ts': '@types-remote-loaded/remote.d.ts' },
});

Roadmap

In the near future, it is planned to expand the functionality and use more TypeScript features.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published