Support the @private
JSDoc directive to exclude private APIs from emitted type declarations
#61651
Open
6 tasks done
π Search Terms
"private jsdoc"
β Viability Checklist
β Suggestion
Could properties, functions, and classes annotated with the
@private
JSDoc directive be omitted from the emitted declarations?tsc should throw an error if a symbol is marked as
@private
, but is actually imported/exported from another declaration file or used in the signature of another symbol like a function parameter or return type. (And therefore isn't actually an internal API.)I'm wary this may break some projects if implemented without an opt-in, so it may require an option to enable this behavior, to preserve backward compatibility.
π Motivating Example
I maintain a svgo, a library that is written in JavaScript and typed with JSDoc directives, and uses tsc to emit declaration files.
As a library normally has an intended public API, afaik there's no need to distribute type declarations for the internal API.
π» Use Cases
This is just to reduce the amount of type declarations served to developers if they aren't needed, reducing the size of the package on npm a little.
No workaround is currently needed, assuming the project is a module that uses
exports
rather thanmain
, as we can limit the public API ourselves. The extra types do not cause any harm, it just makes the final package a little bigger.For projects that use
main
instead ofexports
in theirpackage.json
, this may leak more private APIs that end-users may accidently consume and believe to be part of the public interface.The text was updated successfully, but these errors were encountered: