JSDoc & TSDoc Tags
JSDoc or TSDoc tags can be used to make exceptions for unused or duplicate exports.
Knip tries to minimize configuration and introduces no new syntax. That’s why it hooks into JSDoc and TSDoc tags.
JSDoc comments always start with /**
(not //
) and can be single or
multi-line.
Tags (CLI)
Use arbitrary tags to exclude or include tagged exports from the report. Example:
And then include (+
) or exclude (-
) these tagged exports from the report
like so:
@public
By default, Knip reports unused exports in non-entry files.
Tag the export as @public
and Knip will not report it.
Example:
This tag can also be used to make exceptions in entry files when using —include-entry-exports.
JSDoc: @public and TSDoc: @public
@internal
Internal exports are not meant for public consumption, but only for internal usage such as tests. This means they would be reported in production mode.
Mark the export with @internal
and Knip will not report the export in
production mode.
Example:
In general it’s not recommended to expose and test implementation details, but
exceptions are possible. Those should not be reported as false positives, so
when using production mode you’ll need to help Knip out by tagging them as
@internal
.
@alias
Knip reports duplicate exports. To prevent this, tag one of the exports as
@alias
.
Example:
An alternative solution is to use --exclude duplicates
and exclude all
duplicates from being reported.
@beta
Works identical to @public
. Knip ignores other tags like @alpha
and
@experimental
.
ISC License © 2024 Lars Kappert