@typescript-eslint/project-service
用于 linting 的独立 TypeScript 项目服务封装器 ✨
¥Standalone TypeScript project service wrapper for linting ✨
typescript-eslint 项目服务是 TypeScript "项目服务" API 的封装器。VS Code 等编辑器使用这些 API 以编程方式 "open" 文件并生成 TypeScript 程序以获取类型信息。
¥The typescript-eslint Project Service is a wrapper around TypeScript's "project service" APIs. These APIs are what editors such as VS Code use to programmatically "open" files and generate TypeScript programs for type information.
有关 Lint 用户如何与 Project Service 交互的更多详细信息,请参阅 博客 > 使用 Project Service 进行类型 Linting。
¥See Blog > Typed Linting with Project Service for more details on how lint users interact with the Project Service.
import { createProjectService } from '@typescript-eslint/project-service';
const filePathAbsolute = '/path/to/your/project/index.ts';
const { service } = createProjectService();
service.openClientFile(filePathAbsolute);
const scriptInfo = service.getScriptInfo(filePathAbsolute)!;
const program = service
.getDefaultProjectForFile(scriptInfo.fileName, true)!
.getLanguageService(true)
.getProgram()!;
以下文档是从源代码自动生成的。
¥The following documentation is auto-generated from source code.
Functions
createProjectService()
function createProjectService(settings): ProjectServiceAndMetadata;
Defined in: createProjectService.ts:93
Creates a new Project Service instance, as well as metadata on its creation.
Parameters
Parameter | Type | Description |
---|---|---|
settings | CreateProjectServiceSettings | Settings to create a new Project Service instance. |
Returns
A new Project Service instance, as well as metadata on its creation.
Example
import { createProjectService } from '@typescript-eslint/project-service';
const { service } = createProjectService();
service.openClientFile('index.ts');
Interfaces
CreateProjectServiceSettings
Defined in: createProjectService.ts:63
Settings to create a new Project Service instance with createProjectService.
Properties
ProjectServiceAndMetadata
Defined in: createProjectService.ts:38
A created Project Service instance, as well as metadata on its creation.
Properties
Type Aliases
TypeScriptProjectService
type TypeScriptProjectService = ts.server.ProjectService;
Defined in: createProjectService.ts:33
Shortcut type to refer to TypeScript's server ProjectService.