/** * Top-level typecheck pass — runs after parsing, before evaluation. * * Takes an AST and returns type diagnostics (errors/warnings). * The type map (nodeId → Type) is built as a side effect and can * be used by the IDE for hover types. * * Type errors do NOT block evaluation — they're informational. * The evaluator runs regardless, just like in TypeScript. */ import type { Type } from './types'; import type { DvalaModule } from '../builtin/modules/interface'; import type { AstNode, Ast, SourceMap, SourceMapPosition } from '../parser/types'; import type { SourceCodeInfo } from '../tokenizer/token'; export interface TypeDiagnostic { message: string; severity: 'error' | 'warning'; /** Source location, if available. */ sourceCodeInfo?: SourceCodeInfo; } export interface TypecheckResult { /** Type diagnostics (errors and warnings). */ diagnostics: TypeDiagnostic[]; /** Side-table mapping nodeId → inferred Type. Used by IDE features. */ typeMap: Map; /** Source map for mapping nodeIds to source positions. Used by IDE hover. */ sourceMap?: Map; } export interface TypecheckOptions { /** Resolves file imports. Returns the source code of the file. * Should throw if the file is not found. */ fileResolver?: (importPath: string, fromDir: string) => string; /** Base directory for resolving relative imports. */ fileResolverBaseDir?: string; /** Modules available to import during type checking. */ modules?: DvalaModule[]; /** * Enable constant folding during inference. When `true`, pure calls with * all-literal arguments produce Literal types; literal-cond branches prune * unreachable arms; etc. Takes precedence over the `DVALA_FOLD` env var. * If omitted, the env var default is used. * * See design/archive/2026-04-16_constant-folding-in-types.md. */ fold?: boolean; } /** Initialize the type system — call once before first typecheck. */ export declare function initTypeSystem(): void; /** * Typecheck an AST. Returns diagnostics and a type map. * * Type errors are recovered per-subexpression (assigned Unknown), * so the type map is populated even when errors are found. * This enables IDE features (hover, completions) on partially-typed code. */ export declare function typecheck(ast: Ast, options?: TypecheckOptions): TypecheckResult; /** * Typecheck a single expression (for REPL / quick checks). * Returns the inferred type and any diagnostics. */ export declare function typecheckExpr(nodes: AstNode[], sourceMap?: SourceMap, options?: TypecheckOptions): TypecheckResult & { type: Type; };