A JavaScript library that wraps the TypeScript command-line compiler, providing programmatic API to compile TypeScript files and strings. The library exposes compile(), compileString(), and compileStrings() methods, allowing developers to integrate TypeScript compilation into Node.js workflows without shelling out to tsc. It supports passing compiler options, error callbacks, and can handle multiple source files with reference tags. Version 1.4.1-2 is the latest release, updated sporadically; no active development observed since 2016. Unlike ts-node or ts-jest, this wrapper is minimal and does not include a resolver, so all imports must be fully resolved.
npm install typescript-compilerVerified import paths — ran on the pinned version, not inferred.
Shows how to load the library and compile a simple TypeScript string with compiler arguments.
Use tscArgs string array instead of the options object.
Install a separate TypeScript version and use the 'options' parameter to point to a different compiler? Not supported. Consider using ts-node or a modern wrapper.
Ensure 'typescript' is installed separately if you want to use a different version.
Pass an object with filenames as keys and source code as values.
Run 'npm install typescript-compiler' and ensure it is in your package.json.
Use 'const tsc = require('typescript-compiler')' instead of 'import'.Pass compiler arguments as a string array (e.g., ['--out', 'file.js']) instead of an object.