Typeroll

0.7.7 · active · verified Tue Apr 21

Typeroll is a high-performance TypeScript declaration file generator and bundler designed to consolidate all `.d.ts` files into a single output. It focuses on speed and simplicity, making it ideal for library authors who need to ship a unified declaration file for their packages. Currently at version 0.7.7, it is under active development with a release cadence typically tied to critical bug fixes, performance enhancements, and compatibility with newer TypeScript versions. Its primary differentiator is the ability to produce a highly optimized, single declaration file, often outperforming the built-in `tsc --emitDeclarationOnly` for bundling scenarios, especially in larger projects. It provides a programmatic API for integration into build workflows.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically use Typeroll to bundle TypeScript declaration files. It creates a small dummy project with a `tsconfig.json` and two `.ts` files, then calls the `bundle` function to output a single `.d.ts` file.

import { bundle } from 'typeroll';
import * as path from 'path';
import * as fs from 'fs/promises';

const projectRoot = path.resolve(__dirname, 'my-project');
const entryFile = path.join(projectRoot, 'src', 'index.ts');
const outputDir = path.join(projectRoot, 'dist');
const outputFile = path.join(outputDir, 'my-lib.d.ts');

// Create dummy project files for demonstration
async function setupDummyProject() {
  await fs.mkdir(path.join(projectRoot, 'src'), { recursive: true });
  await fs.mkdir(outputDir, { recursive: true });
  await fs.writeFile(path.join(projectRoot, 'tsconfig.json'), JSON.stringify({
    "compilerOptions": {
      "target": "es2018",
      "module": "esnext",
      "declaration": true,
      "declarationMap": true,
      "outDir": "./dist",
      "strict": true,
      "esModuleInterop": true,
      "skipLibCheck": true,
      "forceConsistentCasingInFileNames": true
    },
    "include": ["src"]
  }, null, 2));
  await fs.writeFile(path.join(projectRoot, 'src', 'index.ts'), 'export * from "./utils";\nexport const version = "1.0.0";\n');
  await fs.writeFile(path.join(projectRoot, 'src', 'utils.ts'), 'export function greet(name: string): string { return `Hello, ${name}!`; }\n');
}

async function runBundle() {
  await setupDummyProject();
  try {
    console.log(`Bundling declarations from ${entryFile}...`);
    const result = await bundle({
      entryPoints: [entryFile],
      tsConfigPath: path.join(projectRoot, 'tsconfig.json'),
      outputFile,
      cwd: projectRoot,
      // Optional: Set to false to disable declaration map generation
      // declarationMap: false,
    });
    console.log(`Declaration bundle written to ${outputFile}`);
    console.log(`
Generated Content Preview:\n---\n${(await fs.readFile(outputFile, 'utf-8')).slice(0, 300)}...\n---`);
    // Clean up dummy project
    await fs.rm(projectRoot, { recursive: true, force: true });
  } catch (error) {
    console.error('Error bundling declarations:', error);
    await fs.rm(projectRoot, { recursive: true, force: true });
    process.exit(1);
  }
}

runBundle();

view raw JSON →