CSpell Types is a comprehensive TypeScript types library that provides the foundational type definitions for the CSpell spell checking ecosystem. It serves as the core type library that enables type-safe configuration and development across all CSpell tools and libraries, offering zero runtime dependencies while providing complete type coverage for the spell checker's configuration schema.
npm install @cspell/cspell-typesimport type { CSpellUserSettings, CSpellSettings, Issue } from "@cspell/cspell-types";For parser-specific types:
import type { Parser, ParsedText, ParseResult } from "@cspell/cspell-types/Parser";CommonJS:
const { CSpellUserSettings } = require("@cspell/cspell-types");import type { CSpellUserSettings, DictionaryDefinition } from "@cspell/cspell-types";
// Define a basic CSpell configuration
const config: CSpellUserSettings = {
version: "0.2",
language: "en",
words: ["TypeScript", "ESLint"],
dictionaries: ["typescript", "node"],
ignoreWords: ["lorem", "ipsum"]
};
// Define a custom dictionary
const customDict: DictionaryDefinition = {
name: "my-dictionary",
path: "./dictionaries/custom.txt",
description: "Custom project dictionary"
};
// Configure language-specific settings
const advancedConfig: CSpellUserSettings = {
version: "0.2",
languageSettings: [
{
languageId: "typescript",
dictionaries: ["typescript", "node"]
}
],
overrides: [
{
filename: "**/*.test.ts",
enabled: false
}
]
};CSpell Types is organized around several key type systems:
CSpellSettings, CSpellUserSettings) for spell checker setupCore configuration interfaces for setting up CSpell spell checking behavior, including basic settings, advanced options, and source tracking.
interface CSpellUserSettings extends CSpellSettings {}
interface CSpellSettings extends FileSettings, LegacySettings {
readonly version?: Version;
}
interface FileSettings extends BaseSetting, ExtendableSettings {}
interface BaseSetting {
enabled?: boolean;
words?: string[];
ignoreWords?: string[];
dictionaries?: DictionaryReference[];
languageSettings?: LanguageSetting[];
}Dictionary configuration types for managing built-in and custom dictionaries, including inline dictionaries and replacement mappings.
type DictionaryDefinition =
| DictionaryDefinitionPreferred
| DictionaryDefinitionCustom
| DictionaryDefinitionAugmented
| DictionaryDefinitionInline;
interface DictionaryDefinitionPreferred extends DictionaryDefinitionBase {
path: DictionaryPath;
}
interface DictionaryDefinitionCustom extends DictionaryDefinitionBase {
path: CustomDictionaryPath;
scope?: CustomDictionaryScope;
}Interfaces for issue reporting, progress tracking, and spell check results with support for custom reporters and emitters.
interface CSpellReporter {
issue: (issue: Issue) => void;
info: MessageEmitter;
debug: DebugEmitter;
error: ErrorEmitter;
progress: ProgressEmitter;
result: ResultEmitter;
}
interface Issue extends TextDocumentOffset {
text: string;
suggestions?: Suggestion[];
issueType: IssueType;
}
interface RunResult {
files: number;
filesWithIssues: Set<string>;
issues: number;
errors: number;
}Text parsing interfaces for extracting and processing content from different file types with support for nested parsing and scope tracking.
interface Parser {
readonly name: ParserName;
parse(content: string, filename: string): ParseResult;
}
interface ParseResult {
readonly content: string;
readonly filename: string;
readonly parsedTexts: Iterable<ParsedText>;
}
interface ParsedText {
readonly text: string;
readonly range: Range;
readonly scope?: Scope;
}type Version = VersionLatest | VersionLegacy;
type VersionLatest = "0.2";
type VersionLegacy = "0.1";
type LanguageId = LanguageIdSingle | LanguageIdMultiple;
type LocaleId = string;
type DictionaryReference = DictionaryRef | DictionaryNegRef;
type DictionaryRef = DictionaryId;
type DictionaryNegRef = `!${DictionaryId}`;
type Glob = SimpleGlob | GlobDef;
type SimpleGlob = string;
interface GlobDef {
glob: string;
root?: string;
}