Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท tsconfig: Type Checking Options

TypeScript stripInternal option

Reference for stripInternal: how the @internal JSDoc tag removes declarations from generated .d.ts files, what it does not hide and its pitfalls.

stripInternal removes any declaration annotated with the @internal JSDoc tag from the .d.ts files that tsc generates. The code still exists in the emitted JavaScript and is still usable inside your package. Only the published type information hides it, so consumers get compile errors if they try to use it.

It is meant for library authors who need helpers to be shared between their own files but not to appear in the public API. The option only has an effect when declaration output is on (declaration or composite).

TypeScript
export class Cache {
  /** @internal */
  _evictAll(): void {}
  get(key: string): string | undefined { return undefined; }
}

Try it

The option changes generated .d.ts files, which this runner does not show. These examples show the runtime side and a rough model of the output.

TypeScript Internal members still exist at runtime

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript What the declaration output keeps

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

JSON
{
  "compilerOptions": {
    "declaration": true,
    "stripInternal": true
  }
}
Part Description
Type boolean. Default: false.
Command line tsc --declaration --stripInternal
Trigger A JSDoc comment containing @internal directly before a declaration (class member, function, interface, type alias, variable, property signature).

Usage notes

  • It is a declaration-emit feature. The JavaScript output still contains the code, so it is not a security boundary or a way to make something private at runtime.
  • Types that mention an @internal declaration in their public signature break: the compiler does not warn, and the generated .d.ts refers to a name that no longer exists. Keep internal types out of public signatures.
  • Tools such as API Extractor offer richer release tags (@public, @beta) if you need more than a single level.
  • With project references, a stripped declaration is hidden from the other projects too, so shared internals between sibling packages must not use the tag.
  • The tag is not recognised in .js files unless declaration emit is configured for JavaScript.
  • Prefer real language features first: private, #private and not exporting a name at all are checked by the compiler and need no option.