网页
综合
更新时间 2026-11-17 01:33:16
Writing documentation - Docs - JSR
自动蜘蛛
jsr.io
正文约 2452 字
View table of contents
Writing documentation is vital for the success of a package. JSR makes it very easy for package authors to have great documentation, because it generates documentation based on the JSDoc-like comments in the package source code.
The supported JSDoc-style features and tags are shared with Deno, and are listed out on Deno’s Supported JSDoc tags page.
This generated documentation is displayed on the package page. This documentation will also be shown to users in their editor in form of completions and hover descriptions.
There are two important pieces to documentation:
Also see this blog post on how to write docs for your package.
To add documentation for a symbol, add a JSDoc comment above the symbol:
The comment can also be a multi-line comment:
For functions, documentation can be added to specific parameters or the return type:
For more complex symbols, it is often good to include an example demonstrating how to use the function:
Interfaces can also be annotated with JSDoc. Their properties and methods can also be annotated:
As seen above, {@link <ident>} can be used to link between symbols in JSDoc. These will become clickable links in the generated documentation.
Classes can be similarly annotated to interfaces and functions:
Not just symbols can be documented. Modules can also be documented. This is useful to give an overview of the module and its exported symbols.
To document a module, add a JSDoc comment at the top of the module file, and include the @module tag after the description:
You can also include examples in module documentation:
By default, if the default entrypoint (the . export) has a module doc comment (a JSDoc comment with the @module tag), that documentation is shown on the “Overview” tab of the package page instead of the README. You can change this behavior in the package’s “Settings” tab by setting the Readme Source to “Readme”, which will always show the README on the Overview tab regardless of whether a module doc exists. Learn more in the documentation section for packages.
By default, when using a wildcard import, the identifier used is mod. For example:
Module authors can customize this default identifier by specifying a custom name in the module’s JSDoc comment using the @module tag. This allows for more descriptive and context-specific import identifiers.
With this annotation, the import statement will now use the custom identifier:
Edit this page on GitHub
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。