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-serviceVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing the TypeScript service and retrieving diagnostic messages for a specific file, also showing access to the underlying `ts.Program`.
Migrate to using `getSourceFile` with the `sourceText` parameter if you need to provide file content, or simply call `getDiagnostics` which can accept `sourceText`.
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.
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.
The `update` method was removed. Use `getSourceFile` or `getDiagnostics` which accept an optional `sourceText` parameter to provide file content.
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');`.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.
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.