output format #
svelte-docinfo outputs JSON describing your project's exported API. Modules contain declarations, and some declarations contain members or props. To see it in practice, jump to the examples.
Top-level structure #
Every surface returns the same envelope, AnalyzeResultJson: the JS API (analyze, analyzeFromFiles, a session's query()), the CLI's JSON, and the
Vite plugin's virtual module.
{
modules: ModuleJson[],
diagnostics: Diagnostic[]
} diagnostics is covered in diagnostics. The CLI emits compact JSON, so an empty project prints {};
parse it with parseAnalyzeResult to restore the defaults.
ModuleJson #
A ModuleJson describes a single source file and its exports:
path: file path relative to the source root (e.g.,"math.ts")declarations: exported items from this modulemoduleComment: the prose of the file-level@modulecomment, if it has anyexamples,deprecatedMessage,seeAlso,since,internalMessage: that comment's tags, as on a declaration (see @module)dependencies: paths of modules this file importsdependents: paths of modules that import this filestarExports:export * from './module'targetsreExports: same-name re-export edges ({name, module, typeOnly, sourceLine}), the forward view ofalsoExportedFrom(see re-exports)externalReExports: direct re-exports from packages ({name, specifier, originalName?, typeOnly, sourceLine})externalStarExports:export * from 'pkg'specifiers as writtenpartial:truewhen the module is a placeholder for a.sveltefile that svelte2tsx failed to transform (seetransform_failed)
Array fields are omitted from JSON when empty and default to [] after parsing.
DeclarationJson #
Each declaration is a DeclarationJson, a discriminated union on kind with nine variants:
"function": addsparameters,returnType,returnTypeInfo,returnDescription,overloads"variable": addstypeInfo, optionaldefaultValue(from@default), andreactivity(see Reactivity)"class": addsmembers,extends,implements,externalTypes"interface": addsmembers,extends,externalTypes,mergedValue"type": addstypeInfo,members,externalTypes,mergedValue"enum": addsmembers(enum values)"component": addsprops,externalTypes,acceptsChildren,cssCustomProperties,lang(Svelte components).acceptsChildrenis set by aSnippet-typedchildrenprop, template use ofchildren, or a legacy component's default<slot />"snippet": addsparameters(exported Svelte template snippets)"namespace": addsmodule, the path of the module projected byexport * as ns from './x'
A name declared as both a value and a type, like the schema pattern export const Foo = z.strictObject({...}) + export type Foo = z.infer<typeof Foo>, produces one
declaration. The type meaning documents like its un-merged equivalent (structure, members, typeInfo), and mergedValue: true marks that the name is also a runtime
value, so generateImport emits import instead of import type. JSDoc falls back to the value declaration's
comment when the type has none, and @nodocs on either declaration excludes the
pair. In JS, a const Foo with a same-named @typedef merges the same way.
Shared fields on all variants:
name,kind: identity. Default exports carryname === "default", except Svelte components, which take their filename-derived name (see re-exports)docComment: JSDoc comment texttypeSignature: the full type as a string, rendered by the TypeScript checker (see module paths)sourceLine: 1-based line number in the source filemodifiers: e.g.,"readonly","static","getter"genericParams: type parameters with constraints and defaultsexamples,deprecatedMessage,seeAlso,throws,since: from standard JSDoc tagsinternalMessage: from@internal, a marker rather than an exclusion (empty string for a bare tag)mutates: from@mutates, aRecord<string, string>of target to description (empty for a target with no description). See tagsalsoExportedFrom: modules that re-export this declarationaliasOf: the canonical{module, name}of a renamed re-exportpartial:truewhen extraction failed partway, so the data is incomplete
Declarations tagged @nodocs are excluded from the output and from the opt-in
duplicate-name check.
Props and members a package contributes (like HTMLButtonAttributes extended by
a component's props) are left out, and the package type is named in externalTypes, unless the $props() destructuring names them.
typeInfo, a structured TypeJson tree beside the flat
type string, appears on variables, type aliases, variable members, component props,
parameters, and tuple elements; functions, function members, overloads, and callback props
carry returnTypeInfo. See structured types.
MemberJson #
Classes, interfaces, types, and enums list MemberJson entries in members, a discriminated union on kind with three variants:
"function": methods and call signatures. Addsparameters,returnType,returnTypeInfo,returnDescription,overloads, and optionaldefaultValue(from@default, documenting the behavior when a callable option is omitted). A property typed by an external function (run?: typeof spawn) is a"variable"with the flat type text rather than the package's overloads and docs; a mixed callable keeps its local signatures"constructor": class constructors and construct signatures. Addsparameters,overloads"variable": properties, accessors, index signatures, and enum values. Adds optionaldefaultValue(from@default),typeInfo, andreactivityfor class fields initialized with a Svelte rune
Function and variable members also carry optional when the property or method
is optional (?, or a mapped modifier such as Partial).
An interface lists its own members, then what each computed extends entry
contributes, as the same type would list them as a type alias's members: interface Foo extends Omit<Base, 'a'> {} lists Base's other properties, and interface Foo extends z.infer<typeof S> {} the
schema's. Members inherited from a named interface or class stay with that base, which extends names.
Nesting is exactly one level deep: members never contain members.
Member name is the source identifier, or a synthesized name where none exists: "constructor" (class constructor), "(construct)" and "(call)" (construct and call signatures on an
interface or type alias), and index-signature names like "[key: string]" (the parameter name as written for an
interface's own; a synthesized key for type aliases and for what an interface's
computed heritage contributes).
ComponentPropJson #
Component declarations have a props array of ComponentPropJson entries, in source order, followed by any props
an external type declares that the $props() destructuring names, in
destructuring order (a legacy export let component
orders by its exports). Each entry has:
name,type: prop name and TypeScript typetypeInfo: structured TypeJson tree, when it adds structureoptional: whether the prop is optionaldescription: from JSDoc on the propdefaultValue: the default's source text, else the@defaulttag textbindable: set when the prop is declared with$bindable(), so<Foo bind:value />works. Every prop of a legacyexport letcomponent is bindableparameters: structured parameters for snippet-typed props (e.g.,Snippet<[text: string]>) and callback props; absent when there are nonereturnTypeandreturnTypeInfo: a callback prop's return type (onpick?: (value: string) => void, or a project alias for one). Its presence is what marks a prop as a callback, including one with no parameters; snippets never carry it. Only call signatures your project declares count, so a prop typed wholly by a package (MouseEventHandler<HTMLButtonElement>, aComponent) has neither fieldexamples,deprecatedMessage,seeAlso,throws,since,internalMessage,mutates: from the prop's own doc comment. On a prop,mutatesdeclares what the component writes into the object or array it's handed
ComponentCssPropertyJson #
A component's cssCustomProperties lists its styling API as ComponentCssPropertyJson entries, documented ones first (see component styling):
name: the property as written,--includeddescription: from a@cssproptagsyntax: a tag's braced syntax, else an@propertyrule'ssyntaxdescriptorfallback: what the style gives the property when unset, as source text: an@propertyrule'sinitial-value, else the first read's fallback (var(--a, var(--b))givesvar(--b))default: a@cssproptag's bracketed default, the author's claim besidefallback; a renderer wanting one value takesdefault ?? fallbacksourceLine: the first read's line, or the tag's for a property never readdocumented: whether a@cssproptag documents it
ParameterJson #
Functions, methods, constructors, overloads, snippets, and snippet or callback props list ParameterJson entries in parameters:
name: parameter name (e.g.,"options"; a rest parameter's dots live inrest, not the name)type: resolved TypeScript type as a stringtypeInfo: structured TypeJson tree, when it adds structureoptional: whether a caller may omit the argument (a?, a default, or in JS a bracketed@param {T} [b])rest: whether the parameter uses rest syntax (...args)description: from@paramdefaultValue: default value expression from the source, if present, else from a bracketed@param {T} [b=0]propertyDescriptions: sub-path to description, from dotted@param obj.proptags on a named object parameter (destructured parameters aren't covered)
ParameterJson deliberately lacks the tag fields ComponentPropJson has: a prop is a named slot with its own documentation, while
a parameter's @example, @deprecated, and similar tags belong on
the enclosing function per the TSDoc spec. Parameters get their docs from @param only.
OverloadJson #
Functions and constructors with multiple signatures list OverloadJson entries in overloads. Each carries only
the fields that vary per signature:
typeSignature: the full overload signature as a stringparameters: this overload's parameters, with its own@paramdescriptionsreturnType: return type for this overload (functions only)returnTypeInfo: structured TypeJson tree for the return type, when it adds structuregenericParams: type parameters for this overloaddocComment: per-overload JSDoc text, if presentreturnDescription: from@returnson this overload
Symbol-scope tags (@example, @deprecated, and the rest) live on
the parent declaration only, read from the primary overload. On a non-primary overload they
emit misplaced_tag and are dropped. See Symbol-scope vs signature-scope.
Reactivity #
reactivity appears on VariableDeclarationJson and VariableMemberJson when the initializer is a value-producing
Svelte rune call: $state, $state.raw, $derived, or $derived.by. Detection is syntactic and runs on every file, so a plain .ts file is treated the same as .svelte.ts or a component script.
Only variables and class fields are annotated, not parameters or destructured bindings. $props and $bindable surface on ComponentPropJson instead.
GenericParamJson #
Declarations and members with type parameters list GenericParamJson entries in genericParams:
name: type parameter name (e.g.,"T")constraint:extendsconstraint, if presentdefaultType: default type, if present
Compact JSON #
Output uses compact JSON via compactReplacer: empty arrays, false booleans, and undefined fields are stripped, so optional, acceptsChildren, partial, rest, bindable, and similar fields vanish at their default. The value key is exempt, so a {kind: "literal", value: false} type node survives.
Parsing with parseAnalyzeResult (or parseModuleJson for one module) restores every default and
validates the shape, so the round-trip is lossless. The helpers are the stable entry point;
the fuz_schema schemas behind them are
exported too.
Raw-JSON consumers (jq, pipelines that skip parsing) must treat absent as false: decl.optional === false fails because
the key is gone. Parse first, or use truthiness checks like if (decl.optional).
Examples #
These show the compact wire form, so empty and default fields are stripped.
A TypeScript function in math.ts:
/** Clamp a number to a range. */
export function clamp(value: number, min: number, max: number): number {
return Math.min(Math.max(value, min), max);
} {
"modules": [
{
"path": "math.ts",
"declarations": [
{
"name": "clamp",
"kind": "function",
"docComment": "Clamp a number to a range.",
"typeSignature": "(value: number, min: number, max: number): number",
"sourceLine": 2,
"parameters": [
{"name": "value", "type": "number"},
{"name": "min", "type": "number"},
{"name": "max", "type": "number"}
],
"returnType": "number"
}
]
}
]
} A Svelte component Card.svelte with a snippet prop, children, an exported
snippet, and a styling hook:
<!-- @component A card with a customizable header. -->
<script lang="ts" module>
/** Default footer snippet. */
export {card_footer};
</script>
<script lang="ts">
import type {Snippet} from 'svelte';
const {
title,
header,
children,
}: {
title: string;
/** Custom header rendering. */
header?: Snippet<[title: string]>;
children?: Snippet;
} = $props();
</script>
<div class="card">
{#if header}{@render header(title)}{:else}<h2>{title}</h2>{/if}
{@render children?.()}
</div>
{#snippet card_footer(text: string)}
<small>{text}</small>
{/snippet}
<style>
.card {
background: var(--card_bg, white);
}
</style> {
"modules": [
{
"path": "Card.svelte",
"declarations": [
{
"name": "Card",
"kind": "component",
"docComment": "A card with a customizable header.",
"sourceLine": 7,
"props": [
{"name": "title", "type": "string"},
{
"name": "header",
"type": "Snippet<[title: string]>",
"typeInfo": {
"kind": "reference",
"name": "Snippet",
"typeArgs": [
{
"kind": "tuple",
"elements": [
{"name": "title", "type": {"kind": "intrinsic", "text": "string"}}
]
}
]
},
"optional": true,
"description": "Custom header rendering.",
"parameters": [
{"name": "title", "type": "string"}
]
},
{"name": "children", "type": "Snippet<[]>", "optional": true}
],
"acceptsChildren": true,
"cssCustomProperties": [
{"name": "--card_bg", "fallback": "white", "sourceLine": 33}
]
},
{
"name": "card_footer",
"kind": "snippet",
"docComment": "Default footer snippet.",
"typeSignature": "Snippet<[text: string]>",
"sourceLine": 27,
"parameters": [
{"name": "text", "type": "string"}
]
}
]
}
]
} A rune module counter.svelte.ts exporting reactive state:
export let count = $state(0);
export const doubled = $derived(count * 2); {
"modules": [
{
"path": "counter.svelte.ts",
"declarations": [
{
"name": "count",
"kind": "variable",
"typeSignature": "number",
"sourceLine": 1,
"reactivity": "$state"
},
{
"name": "doubled",
"kind": "variable",
"typeSignature": "number",
"sourceLine": 2,
"reactivity": "$derived"
}
]
}
]
} A barrel index.ts that re-exports clamp from math.ts under a new name and star-exports other.ts. The rename synthesizes a
declaration with aliasOf that inherits the canonical's signature and docs, the
star export lands on starExports, and the dependency fields connect the
modules. A same-name re-export would instead add the barrel to the canonical's alsoExportedFrom.
// index.ts
export {clamp as clampNumber} from './math.js';
export * from './other.js';
// other.ts
export const TAU = Math.PI * 2; {
"modules": [
{
"path": "index.ts",
"declarations": [
{
"name": "clampNumber",
"kind": "function",
"docComment": "Clamp a number to a range.",
"typeSignature": "(value: number, min: number, max: number): number",
"sourceLine": 1,
"aliasOf": {"module": "math.ts", "name": "clamp"},
"parameters": [
{"name": "value", "type": "number"},
{"name": "min", "type": "number"},
{"name": "max", "type": "number"}
],
"returnType": "number"
}
],
"dependencies": ["math.ts", "other.ts"],
"starExports": ["other.ts"]
},
{
"path": "math.ts",
"declarations": [
{
"name": "clamp",
"kind": "function",
"docComment": "Clamp a number to a range.",
"typeSignature": "(value: number, min: number, max: number): number",
"sourceLine": 2,
"parameters": [
{"name": "value", "type": "number"},
{"name": "min", "type": "number"},
{"name": "max", "type": "number"}
],
"returnType": "number"
}
],
"dependents": ["index.ts"]
},
{
"path": "other.ts",
"declarations": [
{"name": "TAU", "kind": "variable", "typeSignature": "number", "sourceLine": 1}
],
"dependents": ["index.ts"]
}
]
} See the types module for the full schemas, and the API reference for all exported types.