Skip to main content

@typescript-eslint/project-service

npm: @typescript-eslint/project-service v8.33.1

用于 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

ParameterTypeDescription
settingsCreateProjectServiceSettingsSettings to create a new Project Service instance.

Returns

ProjectServiceAndMetadata

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

PropertyTypeDescriptionDefined in
jsDocParsingMode?JSDocParsingModeHow aggressively (and slowly) to parse JSDoc comments.createProjectService.ts:72
options?ProjectServiceOptionsGranular options to configure the project service.createProjectService.ts:67
tsconfigRootDir?stringRoot directory for the tsconfig.json file, if not the current directory.createProjectService.ts:77

ProjectServiceAndMetadata

Defined in: createProjectService.ts:38

A created Project Service instance, as well as metadata on its creation.

Properties

PropertyTypeDescriptionDefined in
allowDefaultProjectundefined | string[]Files allowed to be loaded from the default project, if any were specified.createProjectService.ts:42
lastReloadTimestampnumberThe performance.now() timestamp of the last reload of the project service.createProjectService.ts:47
maximumDefaultProjectFileMatchCountnumberThe maximum number of files that can be matched by the default project.createProjectService.ts:52
serviceProjectServiceThe created TypeScript Project Service instance.createProjectService.ts:57

Type Aliases

TypeScriptProjectService

type TypeScriptProjectService = ts.server.ProjectService;

Defined in: createProjectService.ts:33

Shortcut type to refer to TypeScript's server ProjectService.