microsoft / microsoft/TypeScript

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

Offen
#61,651 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, den motivierenden JavaScript/JSDoc-Fall aus svgo mit der Emission von TypeScript-Deklarationen nachzustellen. Lege fest, wie @private und möglicherweise @access private sich auf emittierte Deklarationen auswirken, einschließlich Fehlern für exportierte oder in Signaturen referenzierte Symbole, und ermittle, ob für die Kompatibilität eine Opt-in-Option erforderlich ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
28/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.