DEV Community

Junaid Ramzan
Junaid Ramzan

Posted on

How not to include internal code in ts declaration file

Typescript provides a mechanism to not include internal code in a declaration file. It can be useful for building a public library.

We can use the stripInternal: true property in our tsconfig.json file. This will enable typescript compiler to check the /** @internal */ JS DOC comment.

main.ts

Add the /** @internal */ JS DOC comment .
By default typescript compiler will ignore this comment but we can enable it in tsconfig.json file.

/** @internal */
function init() {
  console.log('Hello!!')
}

Enter fullscreen mode Exit fullscreen mode

In tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dist",
    "declaration": true,
    "stripInternal": true
  }
}
Enter fullscreen mode Exit fullscreen mode

Compile and check your declaration main.d.ts(in this case it will have the same name as main.ts file) file to not include the init function declaration.

Top comments (0)