diagnostics #
Analysis accumulates errors and warnings without halting, as an array of Diagnostic entries alongside modules in the result.
Identical diagnostics are reported once.
Two-tier error model #
Accumulated (non-fatal): appended to the diagnostics array while analysis continues. Covers type resolution failures, member or prop extraction failures, and JSDoc tag misuse. The result is still valid (see partial).
Thrown (fatal): setup-level problems throw from the public entry points:
- a missing or unloadable
tsconfig.json: one that fails to parse, or anextendstarget that doesn't exist, like SvelteKit's generated tsconfig beforesvelte-kit synchas run - Svelte older than 5
- invalid source options: empty
sourcePaths, a path or absolute pattern outsideprojectRoot, orsourcePathsnot undersourceRoot - conflicting options:
discovery: 'exports'withinclude, orresolveImportwithresolveDependencies: false discovery: 'exports'whenexportsis missing or resolves to no files, or when the source paths share no common prefix- a name collision under
onDuplicates: 'throw'
Wrap analyze / analyzeFromFiles, or createAnalysisSession and query, to handle these. svelte2tsx
failures don't throw; they surface as transform_failed.
Shape #
diagnostics is a plain Array<Diagnostic> beside modules in AnalyzeResultJson. It round-trips through JSON.stringify and parseDiagnostics. Each entry
carries:
kind: discriminant, one per failure mode (see table below)severity:"error"or"warning"file: POSIX-form and relative to the project root, with no leading./; a file outside the project takes the../form. Join withprojectRootto get the absolute path. It names a file, not a module:ModuleJson.pathis relative tosourceRoot, so don't look modules up byfile.line,column: 1-based, optional. Absent when there's no precise position (e.g., a module-level skip). Positions in Svelte files point at the original.sveltesource; one that can't be mapped is omittedmessage: human-readable description, with project-root paths made relative likefile- fields specific to the kind:
symbolName,className,tagName, etc.
Diagnostic kinds #
Severity is fixed per kind: every kind is a warning except transform_failed and module_unreadable, which are always error.
The table below marks each kind's lifecycle. Ingest-time kinds surface when files are ingested and persist with the file until it is re-ingested or deleted, discovery-time comes from file discovery, and unmarked kinds are recomputed on every analysis pass. See the session guide for how they combine.
| kind | When it fires |
|---|---|
type_extraction_failed | Trigger: type resolution threw on a declaration or member. Consequence: it's included with partial: true; typeSignature and typeInfo may be absent. |
signature_analysis_failed | Trigger: function or method signature analysis threw. Consequence: declaration included with partial: true; parameters and overloads may be
empty. |
class_member_failed | Trigger: one member of a class couldn't be analyzed. Consequence: member included with partial: true; siblings still extract normally. |
svelte_prop_failed | Trigger: a Svelte component prop type couldn't be resolved. Consequence: that prop's type falls back to "any"; if the whole props type on $props() is unresolvable, props is empty. When the check for
a children snippet fails, only template use of children can
set acceptsChildren. A legacy export let component whose svelte2tsx output has
no recognized props type reports each exported prop, at its export's line, and has
empty props. |
module_skipped | Trigger: a whole module was skipped during analysis. reason is "not_in_program" (the
file wasn't in the TypeScript program), "no_analyzer" (unsupported extension), or "requires_program" (a Svelte file passed to analyzeModule directly). Consequence: module absent from modules[]. |
module_unreadable | Trigger: a file named by package.json exports couldn't
be read (permission denied, FS error). Consequence: the file is
dropped from the discovered set. Discovery-time. |
import_parse_failed | Trigger: import scanning threw during dependency resolution (not expected: the parse tolerates malformed source). Consequence: the module's dependency edges are dropped; the module still analyzes. Ingest-time. |
duplicate_comment | Trigger: two sources supplied a comment for the same target: an HTML @component comment plus script JSDoc, either with prose or a tag
(commentType: "doc_comment"), or several @module sources in a Svelte file
("module_comment"). Consequence: the higher-priority source wins whole: script JSDoc for
doc comments, its prose and tags replacing the HTML comment's even when the JSDoc
holds tags alone; instance <script>,
then <script module>, then HTML for
module comments, skipping one that holds only dropped tags. |
component_comment_mismatch | Trigger: svelte2tsx, and so editor hover, would document a component
with a different HTML comment than the analyzer: it takes the last comment containing @component anywhere, the analyzer the first with @component at a line start. A second component comment or a passing mention (a backticked @component in a module comment) causes it. Consequence: the analyzer's pick documents the component, and line points at
svelte2tsx's; reword that comment's @component so the two agree. |
misplaced_tag | Trigger: a symbol-scope tag (@example, @deprecated, @internal, @since, @see, @throws, @mutates, @default, @nodocs) on a non-primary overload signature, or a tag that only
describes a declaration (@param, @returns, @mutates, @throws, @default, @nodocs, @cssprop) in a @module comment (then functionName is absent), or a @cssprop on an exported
declaration other than a component (functionName names it). Consequence: the tag is dropped. On an overload, move it to the
primary signature; a @cssprop belongs in the component's doc comment. To
omit a module, use exclude patterns rather than @nodocs.
Overloads a member borrows through its type
(m: typeof fn) never warn; the lending function's
own analysis checks its tags. |
implementation_doc_hidden | Trigger: an overloaded function, method, or constructor documents its
implementation: a TS implementation's JSDoc, or in JS a block with no @overload tag beside the ones that have one, carrying prose or doc tags
(a block of types alone doesn't fire). Consequence: the
implementation's docs are hidden, as TypeScript's hover hides them, and an
implementation @nodocs hides nothing. Move the docs to the first
overload. functionName names the function. |
unknown_param | Trigger: a @param key matches no parameter (a typo, or a
stale doc after a rename). Consequence: the description is dropped. |
unknown_cssprop | Trigger: a component's @cssprop names a property
(propertyName) the component never reads through var(), in
its <style> or its markup's static
style text: a typo, a stale tag, or a property it leaves for its children (reads
aren't resolved across components). line is the tag's. Not emitted when
the style isn't read (css_parse_failed, css_lang_unsupported). Consequence: none; the entry
stays in cssCustomProperties, documented: true. |
cssprop_default_mismatch | Trigger: a component's @cssprop documents a default
([--a=1px], carried in default) that differs from the
fallback its style gives the property (fallback: the first var() read's, or an @property rule's initial-value), compared as text with whitespace runs collapsed, so an
equivalent spelling (red against #f00) warns too. line is the read's. Not emitted when the style isn't read. Consequence: none; the entry keeps both values. |
malformed_tag | Trigger: a @cssprop (tagName) in a
component's doc comment whose text names no -- property: a name without
the dashes, an unclosed {…} or […], an empty tag. line is the tag's. On any other declaration the tag warns misplaced_tag instead. Consequence: the tag is dropped. |
duplicate_tag | Trigger: a @cssprop (tagName) in a
component's doc comment repeats a property (key) an earlier tag names. line is the later tag's. Consequence: the first tag
wins; this one is dropped. |
alias_lost | Trigger: TypeScript dropped the name of an exported type alias
(aliasName) whose right-hand side is an indexed access or conditional,
like z.infer<typeof S> or valibot's v.InferOutput<typeof S>, and svelte-docinfo
can't recover it.
Literal-only unions (z.enum, v.picklist) and brand
intersections don't warn, since they read fine expanded (and an exported brand
recovers its name by matching), and neither do @nodocs aliases. Consequence: unannotated positions document the alias's structure
instead of its name. Where applicable, a nominal symbol
(interface Foo extends z.infer<typeof S> {})
restores it, and documents the inferred properties as its members. |
commonjs_unsupported | Trigger: a JS module that TypeScript doesn't bind as a module (no import/export under bundler/esnext) exports through CommonJS
(module.exports = …, exports.x = …), which isn't modeled. Under node16/nodenext or moduleDetection: 'force' the checker binds
CommonJS exports itself, and its named exports (exports.x, module.exports = {a, b}) document without this
warning; a module.exports = of a function or
literal documents nothing. Consequence: the module is in modules[] with no declarations; its module comment still reads.
Converting it to ES exports documents it. |
css_parse_failed | Trigger: Svelte's parser rejects a component that has a <style>, or a var() in its
markup: malformed CSS, two top-level styles, or markup its loose parsing can't absorb
(any template error under a Svelte before 5.13). Consequence: the
component emits without cssCustomProperties beyond its @cssprop tags; line/column are the parser's. |
css_lang_unsupported | Trigger: a component's <style> names a preprocessor language
(lang="scss", lang="postcss", type="text/less"), carried in lang. Consequence: the style isn't read, so the component emits without cssCustomProperties beyond its @cssprop tags. |
duplicate_declaration | Trigger: a declaration name appears in more than one module, and the
opt-in onDuplicates check is on (for packages with a flat export
namespace). declarationName and modules name the conflict; modules holds ModuleJson.path values, unlike file. Consequence: none beyond the diagnostic, unless onDuplicates is 'warn' (logs) or 'throw'. |
transform_failed | Trigger: svelte2tsx threw on a .svelte file. Consequence: the file's ModuleJson is a
placeholder (partial: true, empty declarations). Its default and namespace re-exports document as partial components or namespaces (a <script module> name stays a bare
variable), and a star over it is one resolveExportSurface reports unresolved. Ingest-time. |
source_map_failed | Trigger: the source map svelte2tsx produced for a .svelte file couldn't be parsed. Consequence: analysis
continues without position mapping: other diagnostics for the file omit line/column, and declaration sourceLines point
into the generated TypeScript. Ingest-time. |
resolver_failed | Trigger: the import resolver threw on specifier (as
opposed to returning null for an external). Consequence: the dependency edge is deferred and retried when a later setFile / setFiles adds files or the importer changes; the diagnostic clears once
it resolves. Ingest-time. |
Use byKind to narrow to one variant with typed fields:
import {byKind} from 'svelte-docinfo';
for (const d of byKind(diagnostics, 'misplaced_tag')) {
// d.tagName, d.functionName, d.file, d.line are typed
console.warn(`${d.functionName}: move @${d.tagName} to the primary overload`);
}severity vs partial #
severity says how loud to be about a problem. partial: true says a declaration or member has
incomplete data, from type_extraction_failed, signature_analysis_failed, or class_member_failed, and a ModuleJson is partial when it's a transform_failed placeholder. svelte_prop_failed sets no flag; the prop's type falls back to any. Check partial directly instead of matching diagnostics by
file and line.
Helpers #
Read helpers for the diagnostics array:
- hasErrors, hasWarnings: boolean checks by severity
- errorsOf, warningsOf: filter by severity
- byKind: filter by kind, narrowed to the matching variant
- formatDiagnostic: format as
'./file.ts:10:5: error: message'(the'./'prefix is fixed)
See diagnostics.ts for the schemas and helpers.
Consuming diagnostics #
The CLI includes diagnostics in its JSON
output, omitted when empty (parseAnalyzeResult restores []). Progress messages go to stderr; structured diagnostics appear only in the
JSON:
npx svelte-docinfo | jq '.diagnostics | group_by(.kind) | map({kind: .[0].kind, count: length})' Programmatically:
import {analyzeFromFiles, errorsOf, formatDiagnostic, byKind} from 'svelte-docinfo';
const {modules, diagnostics} = await analyzeFromFiles({projectRoot: process.cwd()});
// File paths in diagnostics are already project-relative.
for (const d of errorsOf(diagnostics)) {
console.error(formatDiagnostic(d));
}
// Specific check: any @param typos?
const stale = byKind(diagnostics, 'unknown_param');
if (stale.length) {
console.warn(`${stale.length} stale @param tag(s); fix or remove`);
} The Vite plugin's virtual module exports diagnostics too, so an app can render doc warnings without re-running analysis:
import {modules, diagnostics} from 'virtual:svelte-docinfo';
// the diagnostics subpath keeps the TypeScript compiler out of the client bundle
import {hasErrors} from 'svelte-docinfo/diagnostics.js';
if (hasErrors(diagnostics)) {
// surface in the UI or fail the build
}