/** * Common type definitions for svelte-fast-check */ /** svelte2tsx SourceMap type (mappings is string) */ interface Svelte2TsxSourceMap { mappings: string; names: string[]; sources: string[]; version: number; } /** Map type used in ConversionResult */ type SourceMapData = Svelte2TsxSourceMap | { mappings: string; sources: never[]; }; /** svelte2tsx conversion result */ interface ConversionResult { /** Original .svelte file path */ sourcePath: string; /** Generated .svelte.tsx file path */ outputPath: string; /** Sourcemap data */ map: SourceMapData; /** Whether conversion succeeded */ success: boolean; /** Error message (on failure) */ error?: string; } /** TypeScript diagnostic (tsgo output) */ interface Diagnostic { /** File path (.svelte.tsx) */ file: string; /** 1-based line number */ line: number; /** 1-based column number */ column: number; /** TS error code (e.g., 2304), 0 for svelte warnings */ code: number; /** Error message */ message: string; /** Severity */ severity: "error" | "warning"; /** Source of the diagnostic */ source?: "ts" | "svelte"; } /** Mapped diagnostic (original .svelte location) */ interface MappedDiagnostic extends Diagnostic { /** Original .svelte file path */ originalFile: string; /** Original 1-based line number */ originalLine: number; /** Original 1-based column number */ originalColumn: number; /** Svelte warning code (e.g., 'state_referenced_locally') - only for svelte warnings */ svelteCode?: string; } /** Svelte compiler warning (from svelte.compile) */ interface SvelteWarning { /** Warning code (e.g., 'state_referenced_locally') */ code: string; /** Warning message */ message: string; /** File path */ filename: string; /** Start position */ start: { line: number; column: number; character: number; }; /** End position */ end: { line: number; column: number; character: number; }; /** Code frame */ frame?: string; } /** svelte-fast-check execution result */ interface CheckResult { /** List of diagnostics */ diagnostics: MappedDiagnostic[]; /** Error count */ errorCount: number; /** Warning count */ warningCount: number; /** Execution time (ms) */ duration: number; } /** svelte-fast-check configuration */ interface FastCheckConfig { /** Project root directory */ rootDir: string; /** Source directory (where svelte files are located) */ srcDir: string; /** Cache directory name (default: .fast-check) */ cacheDir?: string; /** tsconfig path aliases */ paths?: Record; /** File patterns to exclude */ exclude?: string[]; /** Additional file patterns to include */ include?: string[]; /** SvelteKit types directory */ svelteKitTypesDir?: string; /** @types packages to include (empty array disables auto-loading) */ types?: string[]; } /** * Svelte compiler warnings module * * Collects warnings from svelte.compile({ generate: false }) * Runs in parallel with the type checking pipeline. */ /** * Collect warnings from all svelte files (parallel) */ declare function collectAllSvelteWarnings(config: FastCheckConfig): Promise; /** * Collect warnings with incremental caching (only process changed files) */ declare function collectChangedSvelteWarnings(config: FastCheckConfig): Promise; /** * Error output formatting module */ /** * Format diagnostic in svelte-check style * * Output format: * /path/to/file.svelte:10:5 * Error: Cannot find name 'foo'. (ts) * let x: string = 123; * > ^ * * For svelte warnings: * /path/to/file.svelte:10:5 * Warning: This reference only captures... (svelte) */ declare function formatDiagnostic(d: MappedDiagnostic, rootDir: string): string; /** * Print all diagnostics */ declare function printDiagnostics(diagnostics: MappedDiagnostic[], rootDir: string): void; /** * Print summary */ declare function printSummary(result: CheckResult): void; /** * Print raw diagnostics (for Phase 1) */ declare function printRawDiagnostics(diagnostics: Diagnostic[]): void; /** * Worker orchestration * * Runs typecheck and compiler workers in parallel */ /** Warning filter function type (compatible with svelte.config.js compilerOptions.warningFilter) */ type WarningFilter = (warning: { code: string; message: string; filename?: string; }) => boolean; interface RunOptions { /** Incremental mode (convert only changed files) */ incremental?: boolean; /** Raw mode (output without filtering/mapping) */ raw?: boolean; /** Quiet mode (suppress progress output) */ quiet?: boolean; /** Enable svelte compiler warnings (default: true) */ svelteWarnings?: boolean; /** Use svelte.config.js for warningFilter (default: true) */ useSvelteConfig?: boolean; /** Custom path to svelte.config.js (auto-detected if not specified) */ svelteConfigPath?: string; /** Custom warning filter function (takes precedence over svelte.config.js) */ warningFilter?: WarningFilter; } /** * Run svelte-fast-check */ declare function run(config: FastCheckConfig, options?: RunOptions): Promise; /** * svelte2tsx conversion module * * Converts .svelte files to .svelte.tsx under .fast-check/tsx/. * Sourcemaps are stored in .fast-check/maps/ for incremental builds. * Uses Promise.all + async IO for parallel conversion. */ /** Dynamic tsconfig path */ declare const getGeneratedTsconfigPath: (config: FastCheckConfig) => string; /** * Initialize cache directories */ declare function ensureCacheDir(config: FastCheckConfig): void; /** * Find all .svelte files and convert to .svelte.tsx (parallel with Promise.all) */ declare function convertAllSvelteFiles(config: FastCheckConfig): Promise; /** * Convert only changed files (mtime-based, parallel) + delete orphan tsx files */ declare function convertChangedFiles(config: FastCheckConfig): Promise; /** * Return all sourcemaps as a Map */ declare function buildSourcemapMap(results: ConversionResult[]): Map; interface GenerateTsconfigOptions { /** Whether to use incremental build (default: true) */ incremental?: boolean; } /** * Generate .fast-check/tsconfig.json for tsgo * * Why we don't use "extends" in generated tsconfig: * - tsgo has compatibility issues with some tsconfig options (rootDirs, certain path resolutions) * - Instead, we read the project's tsconfig.json (following extends chain), merge settings, * and generate a standalone tsconfig with only the options tsgo supports well * * Reads the project's tsconfig.json as a base, * and overrides only the settings required by fast-check. */ declare function generateTsconfig(config: FastCheckConfig, options?: GenerateTsconfigOptions): Promise; /** * False positive filtering module * * This module filters out false positive TypeScript errors that occur due to: * * 1. svelte2tsx generated code: svelte2tsx converts .svelte files to .tsx, * generating helper code that can produce spurious type errors. * - Uses Ωignore_startΩ and Ωignore_endΩ comment markers * - Ported from svelte-check's DiagnosticsProvider logic * * 2. tsgo vs tsc differences: We use tsgo (TypeScript Go port) instead of tsc. * tsgo has stricter or different type inference in some cases, causing errors * that tsc (used by svelte-check) does not report. * * Known tsgo issues related to our filters: * - https://github.com/microsoft/typescript-go/issues/2060 * "Typescript-go does not infer large generics due to maximum length" * - https://github.com/microsoft/typescript-go/issues/1616 * "Type Ordering" issues with complex generic inference * * Filters from svelte-check (common to both tsc and tsgo): * - TS2454: USED_BEFORE_ASSIGNED - export let props pattern * - TS7028: UNUSED_LABEL - $: reactive statements * - TS6387: DEPRECATED_SIGNATURE - $$_ generated variables * - TS2300/1117: DUPLICATE_IDENTIFIER - JSX attribute patterns * - TS17001: DUPLICATED_JSX_ATTRIBUTES - valid in Svelte * - TS2741: PROPERTY_MISSING - bind:this type mismatch * - Ignore region filtering * * Filters for tsgo-specific issues (tsc does not report these): * - TS2345: ARG_TYPE_NOT_ASSIGNABLE in __sveltets_2_ensureComponent * - tsgo fails to infer complex generic types (e.g., Storybook's defineMeta) * - tsc correctly infers these types * - Related: https://github.com/microsoft/typescript-go/issues/2060 * * - TS7006/7031: IMPLICIT_ANY in component prop callbacks * - tsgo doesn't infer callback parameter types in generated code * - tsc handles these correctly * * - TS2307: MODULE_NOT_FOUND for asset imports (.avif, .png, etc.) * - Both report this, but bundlers handle it at runtime * * - TS2614: NO_EXPORTED_MEMBER for .svelte type exports * - Module resolution differences between tsgo and tsc * * - TS2322: TYPE_NOT_ASSIGNABLE for Snippet type compatibility * - tsgo loses `unique symbol` when accessed through a property * - svelte2tsx generates Snippet types with `unique symbol` that tsgo can't match * - tsc handles these correctly * - Issue: https://github.com/microsoft/typescript-go/issues/1682 */ /** * Apply all filtering rules to remove false positives */ declare function filterFalsePositives(diagnostics: Diagnostic[], tsxContents: Map): Diagnostic[]; /** * Load TSX file contents (supports new path structure) */ declare function loadTsxContents(files: string[], rootDir: string): Map; /** * Extract .svelte.tsx file paths */ declare function extractTsxFiles(diagnostics: Diagnostic[]): string[]; /** * Sourcemap-based location mapping module * * Converts error locations from .svelte.tsx files under .fast-check/tsx/ * to original .svelte file locations under src/. */ /** * Extract original svelte path from tsx path * .fast-check/tsx/src/routes/+layout.svelte.tsx -> src/routes/+layout.svelte * * @param rootDir - Project root directory * @param tsxPath - Path to .svelte.tsx file (relative or absolute) * @param cacheDir - Cache directory name (default: '.fast-check') */ declare function tsxPathToOriginal(rootDir: string, tsxPath: string, cacheDir?: string): string; /** * Map all diagnostics to original locations * * @param diagnostics - List of diagnostics to map * @param sourcemaps - Map of tsx file paths to sourcemap data * @param rootDir - Project root directory * @param tsxContents - Optional map of tsx file contents (for store error detection) * @param cacheDir - Cache directory name (default: '.fast-check') */ declare function mapDiagnostics(diagnostics: Diagnostic[], sourcemaps: Map, rootDir: string, tsxContents?: Map, cacheDir?: string): MappedDiagnostic[]; /** * Filter out negative line numbers (mapping failure cases) */ declare function filterNegativeLines(diagnostics: MappedDiagnostic[]): MappedDiagnostic[]; /** * tsc output parsing module * * Parses tsc stdout into a Diagnostic array. */ /** * Parse tsc output * * tsc output format examples: * src/routes/+page.svelte.tsx(10,5): error TS2304: Cannot find name 'foo'. * src/lib/utils.ts(25,10): error TS2322: Type 'string' is not assignable to type 'number'. */ declare function parseTscOutput(output: string): Diagnostic[]; /** * Count diagnostics by severity */ declare function countDiagnostics(diagnostics: Diagnostic[]): { errorCount: number; warningCount: number; }; export { type CheckResult, type ConversionResult, type Diagnostic, type FastCheckConfig, type RunOptions as FastCheckOptions, type MappedDiagnostic, type SourceMapData, type SvelteWarning, type WarningFilter, buildSourcemapMap, collectAllSvelteWarnings, collectChangedSvelteWarnings, convertAllSvelteFiles, convertChangedFiles, countDiagnostics, ensureCacheDir, extractTsxFiles, filterFalsePositives, filterNegativeLines, formatDiagnostic, generateTsconfig, getGeneratedTsconfigPath, loadTsxContents, mapDiagnostics, parseTscOutput, printDiagnostics, printRawDiagnostics, printSummary, run as runFastCheck, tsxPathToOriginal };