microsoft / microsoft/TypeScript

Only emit declarations for code that has an /** @external */ JSDoc annotation

Open
#27,125 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Search Terms

external emit declaration

Problem

When working with the --stripInternal compiler flag, you want to create a clean declaration file that only exposes the stuff your library users should use.
You as library developer must add the /* @internal */ annotations to all the parts of your code you don't want in the declaration file. 'Sloppy developers in the team' forget to set this annotation and expose stuff without realizing it.

Suggestion

It would be handy if we could reverse this.
We could start with an empty declaration file when a compiler flag --onlyExternal is set and only expose the things that have an /* @external */ JSDoc annotation

  • /* @external */ exposes the 'item' and the 'parent path' to acces it.
  • /* @internal */ used inside an /* @external */ parent hides the 'item' and and all its children.
  • /* @external */ used inside an /* @internal */ parent is ignored and stays internal.

Remarks

  • When using the /* @internal */ annotation, you mostly try to place it on top level structures (like namespaces). In these cases it is not a problem when code is added to the namespace. It is mostly a problem when new files or namespaces are added.
  • When using the suggested /* @external */ annotation, you normally will place it more deeply, like on specific functions, variables or classes to expose.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by investigating TypeScript's compiler flag handling and declaration emit behavior, especially how --stripInternal currently filters declarations. Define tests for --onlyExternal, including nested @external and @internal annotations, before implementing the requested filtering semantics. Done means declaration output contains only permitted externally annotated items and their parent paths, with the stated nesting rules.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.