microsoft / microsoft/TypeScript

Support the `@private` JSDoc directive to exclude private APIs from emitted type declarations

未关闭
#61,651 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Awaiting More Feedback Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

🔍 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.

Source

The @private tag marks a symbol as private, or not meant for general use. Private members are not shown in the generated output…

The @private tag is equivalent to @access private.

https://jsdoc.app/tags-private

Based on this, it may be worth also doing it for @access private as well.

Private members are not shown in the generated output…

https://jsdoc.app/tags-access

📃 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 than main, 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 of exports in their package.json, this may leak more private APIs that end-users may accidently consume and believe to be part of the public interface.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 TypeScript 声明生成来复现 svgo 中作为动机的 JavaScript/JSDoc 案例。定义 @private 以及可能的 @access private 如何影响生成的声明,包括对导出符号或在签名中引用的符号报错,并确定是否需要 opt-in 选项来实现兼容性。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, typescript
领域
compilers
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
28/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。