Volt.Builder.Declarations (Volt v0.23.0)

Copy Markdown View Source

Writes the type declarations of a library entry as one .d.ts.

Each TypeScript module of the entry's graph is emitted through OXC's isolated declarations, which need explicit types on exported declarations and report the ones they cannot infer; a plugin-owned module, such as a .vue file, is declared by its plugin. The declarations are then bundled the way rollup-plugin-dts bundles them: the graph is walked from the entry along the declarations' own imports, so modules that only hold types are included; only the declarations the entry's exports reach are kept, along with ambient declarations such as declare module; imports of other packages are hoisted and merged; and two modules declaring the same name are told apart by renaming the one further from the entry.

Declarations are module-scoped, so names resolve at the top level of each module: an identifier is the module's own declaration of that name, or what the module imports under that name. Property names, type parameters and parameters are left alone.

Summary

Functions

Bundle the declarations of the module at entry into one .d.ts source.

Functions

bundle(entry, ctx)

@spec bundle(Path.t(), Volt.Builder.Context.t()) ::
  {:ok, String.t()} | {:error, term()}

Bundle the declarations of the module at entry into one .d.ts source.

Returns {:error, {:declarations, path, reason}} when a module's declarations cannot be emitted (reason is then the emitter's diagnostics) or hold a construct the bundler does not handle (reason is then a message).