{"id":15000,"library":"typescript-service","title":"TypeScript Diagnostic Service","description":"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.","status":"abandoned","version":"2.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/unlight/typescript-service","tags":["javascript","typescript"],"install":[{"cmd":"npm install typescript-service","lang":"bash","label":"npm"},{"cmd":"yarn add typescript-service","lang":"bash","label":"yarn"},{"cmd":"pnpm add typescript-service","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the underlying TypeScript compiler API (e.g., `ts.Program`, `ts.CompilerOptions`, `ts.DiagnosticWithLocation`) that this service wraps and exposes.","package":"typescript","optional":false}],"imports":[{"note":"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.","wrong":"const { createService } = require('typescript-service');","symbol":"createService","correct":"import { createService } from 'typescript-service';"},{"note":"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.","wrong":"const ts = require('typescript');","symbol":"ts.Program, ts.DiagnosticWithLocation","correct":"import * as ts from 'typescript';"}],"quickstart":{"code":"import { createService } from 'typescript-service';\nimport * as path from 'path';\n\nconst projectRoot = process.cwd();\nconst configFile = path.join(projectRoot, 'tsconfig.json');\nconst exampleFile = path.join(projectRoot, 'src', 'example.ts');\n\n// Ensure a tsconfig.json exists for demonstration\n// In a real project, this file would be present.\n// For quick testing, you might need to create a minimal tsconfig.json and src/example.ts\n// e.g., tsconfig.json: { \"compilerOptions\": { \"target\": \"es5\", \"module\": \"commonjs\", \"strict\": true } }\n// e.g., src/example.ts: export const a: string = 123; // This will produce a diagnostic\n\nconst service = createService({ configFile });\nconst diagnostics = service.getDiagnostics(exampleFile);\n\nif (diagnostics.length > 0) {\n  console.log(`Diagnostics for ${exampleFile}:`);\n  diagnostics.forEach(diagnostic => {\n    const message = typeof diagnostic.messageText === 'string'\n      ? diagnostic.messageText\n      : diagnostic.messageText.messageText;\n    console.log(`  [TS${diagnostic.code}] ${message} (Line: ${diagnostic.start?.line + 1}, Char: ${diagnostic.start?.character + 1})`);\n  });\n} else {\n  console.log(`No diagnostics found for ${exampleFile}.`);\n}\n\n// You can also get the underlying ts.Program instance\nconst program = service.getProgram();\nconsole.log(`\nTypeScript program contains ${program.getSourceFiles().length} source files.`);","lang":"typescript","description":"Demonstrates initializing the TypeScript service and retrieving diagnostic messages for a specific file, also showing access to the underlying `ts.Program`."},"warnings":[{"fix":"Migrate to using `getSourceFile` with the `sourceText` parameter if you need to provide file content, or simply call `getDiagnostics` which can accept `sourceText`.","message":"The `update` method was removed in version 2.0.0. Code relying on this method will break.","severity":"breaking","affected_versions":">=2.0.0"},{"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.","message":"The 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.","severity":"breaking","affected_versions":">=2.0.3"},{"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.","message":"While 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"The `update` method was removed. Use `getSourceFile` or `getDiagnostics` which accept an optional `sourceText` parameter to provide file content.","cause":"Attempting to use the `update` method, which was removed in version 2.0.0.","error":"TypeError: service.update is not a function"},{"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');`.","cause":"Incorrect module import syntax (e.g., `require` in an ESM context) or the package is not correctly installed/resolved.","error":"Error: Cannot find module 'typescript-service' or 'require is not defined'"},{"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.","cause":"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.","error":"TS2345: Argument of type 'string | number | boolean' is not assignable to parameter of type 'string'."},{"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.","cause":"The `getSourceFile` method failed because the specified file was not included in the `tsconfig.json`'s scope.","error":"Error: getSourceFile fail fixed if file is not defined in tsconfig"}],"ecosystem":"npm"}