https://github.com/selectel/ts-check
https://github.com/selectel/ts-check
typescript typescript-library
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/selectel/ts-check
- Owner: selectel
- License: mit
- Created: 2025-02-03T12:52:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-03T18:28:48.000Z (over 1 year ago)
- Last Synced: 2025-05-30T23:11:00.015Z (about 1 year ago)
- Topics: typescript, typescript-library
- Language: TypeScript
- Homepage:
- Size: 35.2 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CLI utility for checking types using TypeScript server
Type checking is performed using the TypeScript server [project system](https://github.com/microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29#project-system).
## Requirements
This package requires at least typescript 5.
## Install
Install `typescript` and `@selectel/ts-check` using your package manager.
```bash
npm install --save-dev typescript @selectel/ts-check
```
## Usage
```bash
npx ts-check []
```
The arguments are a list of files to check. Other options:
```
ts-check [options] []
Checking types for the passed list of files
Options:
--no-color Disable colors for output [boolean]
-b, --code-lines-before Print lines of code before error [number]
-a, --code-lines-after Print lines of code after error [number]
--gitlab-report Path to gitlab code quality report file [string]
-v, --verbose Run with verbose logging [boolean]
-h, --help Show a help message [boolean]
--files A list of files for type checking [Array]
```
## GitLab code quality
Define a GitLab job to run `ts-check`.
_.gitlab-ci.yml_:
```yaml
ts-check:
image: node:20-alpine
script:
- npm ci
- npx ts-check --gitlab-report ts-check-report.json
artifacts:
reports:
codequality: ts-check-report.json
```
## TypeScript server
The package also provides an simple interface for communicating with the TypeScript server.
```ts
import ts from "typescript";
import { TsServer } from "@selectel/ts-check";
const file = "test.ts";
// Request to open file
const openRequest: ts.server.protocol.OpenRequest = {
seq: 1,
type: "request",
command: ts.server.protocol.CommandTypes.Open,
arguments: { file },
};
// Request to search for errors in a file
const diagnosticRequest: ts.server.protocol.SemanticDiagnosticsSyncRequest = {
seq: 2,
type: "request",
command: ts.server.protocol.CommandTypes.SemanticDiagnosticsSync,
arguments: { file },
};
// Create a server instance
const server = new TsServer();
// RxJs observable with server responses
const responses$ = server.listen();
// Subscribe to server responses
responses$.subscribe(console.log);
// Sending requests to the server
server.send(openRequest);
server.send(diagnosticRequest);
```
## Other
* [Documentation of TypeScript server](https://github.com/microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29)
* [Example usage of TypeScript server](https://github.com/mmorearty/tsserver-example)
* [GitLab Code Quality documentation](https://docs.gitlab.com/ee/ci/testing/code_quality.html)