Registry / devops / typescript-service

typescript-service

JSON →
library2.0.3jsnpmunverified

The `typescript-service` package, currently at version 2.0.3 and last updated in August 2018, provides a programmatic interface to interact with the TypeScript language service. Its primary function is to help retrieve diagnostic messages from TypeScript source files by abstracting the direct usage of the complex `typescript` module API. The library allows users to create a service instance by specifying a `tsconfig.json` file and optional `compilerOptions`, then retrieve diagnostics for specific files. However, due to its age and lack of maintenance for over seven years, it is considered abandoned. This makes it highly improbable to be compatible with current major versions of TypeScript (e.g., TypeScript 6.x) or contemporary Node.js environments, and it has no active release cadence. Its key differentiator of simplifying TypeScript diagnostics is now overshadowed by its severe compatibility issues.

npm install typescript-service
INSTALL
IMPORT
SIG · TYPESCRIPT-SERVICE
T
typescript-service
devopsjavascriptv2.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createService
import { createService } from 'typescript-service';
const { createService } = require('typescript-service');
The package's usage example in the README uses ES module syntax. However, given its publish date (2018) and Node.js engine requirement (>=6), it likely ships as CommonJS or expects bundling. Direct ESM consumption in modern Node.js might require specific module resolution configurations.
ts.Program, ts.DiagnosticWithLocation
import * as ts from 'typescript';
const ts = require('typescript');
These types and objects are fundamental to the `typescript-service` API but are exposed directly from the `typescript` package, which is an implicit peer dependency.

Demonstrates initializing the TypeScript service and retrieving diagnostic messages for a specific file, also showing access to the underlying `ts.Program`.

import { createService } from 'typescript-service'; import * as path from 'path'; const projectRoot = process.cwd(); const configFile = path.join(projectRoot, 'tsconfig.json'); const exampleFile = path.join(projectRoot, 'src', 'example.ts'); // Ensure a tsconfig.json exists for demonstration // In a real project, this file would be present. // For quick testing, you might need to create a minimal tsconfig.json and src/example.ts // e.g., tsconfig.json: { "compilerOptions": { "target": "es5", "module": "commonjs", "strict": true } } // e.g., src/example.ts: export const a: string = 123; // This will produce a diagnostic const service = createService({ configFile }); const diagnostics = service.getDiagnostics(exampleFile); if (diagnostics.length > 0) { console.log(`Diagnostics for ${exampleFile}:`); diagnostics.forEach(diagnostic => { const message = typeof diagnostic.messageText === 'string' ? diagnostic.messageText : diagnostic.messageText.messageText; console.log(` [TS${diagnostic.code}] ${message} (Line: ${diagnostic.start?.line + 1}, Char: ${diagnostic.start?.character + 1})`); }); } else { console.log(`No diagnostics found for ${exampleFile}.`); } // You can also get the underlying ts.Program instance const program = service.getProgram(); console.log(` TypeScript program contains ${program.getSourceFiles().length} source files.`);
Debug
Known issues
breakingThe `update` method was removed in version 2.0.0. Code relying on this method will break.
fix
Migrate to using `getSourceFile` with the `sourceText` parameter if you need to provide file content, or simply call `getDiagnostics` which can accept `sourceText`.
affects: >=2.0.0
breakingThe package is effectively abandoned, with no updates since August 2018. It is highly unlikely to be compatible with modern TypeScript versions (e.g., TS 5.x, 6.x) or recent Node.js releases, leading to potential type mismatches, runtime errors, or unexpected behavior due to API changes in the TypeScript compiler itself.
fix
Consider using alternative, actively maintained libraries for programmatic TypeScript diagnostics, or interact directly with the `typescript` package API if a wrapper is not strictly necessary. Attempting to use this package with recent TypeScript versions will likely require significant polyfilling or workarounds.
affects: >=2.0.3
gotchaWhile the README uses an ESM `import` statement, the package's age and `engines.node` requirement (>=6) suggest it may ship as CommonJS. Consuming it in a pure ESM Node.js project without a build step or explicit module configuration might lead to `require is not defined` or `Cannot find module` errors.
fix
If encountering module resolution issues in an ESM project, verify the package's actual output format. You may need to adjust your `tsconfig.json`'s `module` and `moduleResolution` options, use a bundler, or resort to dynamic `import()` for CommonJS modules in an ESM context.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: service.update is not a function
Attempting to use the `update` method, which was removed in version 2.0.0.
fix
The `update` method was removed. Use `getSourceFile` or `getDiagnostics` which accept an optional `sourceText` parameter to provide file content.
Error: Cannot find module 'typescript-service' or 'require is not defined'
Incorrect module import syntax (e.g., `require` in an ESM context) or the package is not correctly installed/resolved.
fix
Ensure `npm install typescript-service` is run. For module issues, check your project's `type` in `package.json` and `tsconfig.json`'s `module` and `moduleResolution` settings. If your project is ESM, try `import { createService } from 'typescript-service';`. If CJS, try `const { createService } = require('typescript-service');`.
TS2345: Argument of type 'string | number | boolean' is not assignable to parameter of type 'string'.
Compatibility issues with newer TypeScript versions where `ts.Diagnostic` or other types have changed or become stricter, leading to type mismatches when using the old API.
fix
This often indicates a fundamental incompatibility with your current TypeScript version. You may need to either downgrade your TypeScript version to one closer to the package's last update (e.g., TypeScript 3.x), or switch to an actively maintained library. Manual type assertions (`as any`) might temporarily silence errors but won't resolve underlying runtime issues.
Error: getSourceFile fail fixed if file is not defined in tsconfig
The `getSourceFile` method failed because the specified file was not included in the `tsconfig.json`'s scope.
fix
Ensure all files you intend to process with `typescript-service` are included in the `files`, `include`, or `references` sections of your `tsconfig.json`. Alternatively, provide the `sourceText` parameter to `getDiagnostics` or `getSourceFile` if the file is outside the configured project scope.
Upgrade
Version history
2.0.3latest on npm
Audit
Dependencies
typescriptrequiredProvides the underlying TypeScript compiler API (e.g., `ts.Program`, `ts.CompilerOptions`, `ts.DiagnosticWithLocation`) that this service wraps and exposes.
Agent activity
4 hits · last 30 days
node
4
Resources
typescript-service — npm install typescript-service · libregistry