• Home
  • Today I learned
  • We can decorate an export with @internal to prevent unnecessary d.ts types

We can decorate an export with @internal to prevent unnecessary d.ts types

This article was published on Mar 09, 2021, and takes less than a minute to read.

While creating a JS lib using TypeScript, it's common we want to generate .d.ts files (types).

But let's say you export something for testing purposes but it's totally internal usage and the type for that should not be created. To solve that we can use an option in tsconfig called stripInternal combined with @internal JSDocs:

tsconfig.json
  {
    "compileOptions": {
        // ... your config
        "stripInternal": true
    }
  }
main.ts
/**
 * Days available in a week
 * @internal
 */
export const daysInAWeek = 7;

/**
  * Calculate how much someone earns in a week 
  */
export function weeklySalary(dayRate: number) {
  return daysInAWeek * dayRate;
dist/main.d.ts
/** Calculate how much someone earns in a week */
export declare function weeklySalary(dayRate: number): number;

Resources