Skip to main content

Create declaration files for your processes

This script improves IntelliSense (auto-completion) for ADITO modules in VS Code by generating TypeScript declaration files (.d.ts) for your process modules.

Background for needing this script

VS Code is optimized for fast JavaScript development and IntelliSense. It indexes all JS files in your workspace and provides completions for all functions, variables, and classes it finds. VS Code includes completions for all installed @types/<anyType> dependencies, and offers completions for symbols from node_modules that are already imported.

This leads to a limitation:

  • If you import a specific symbol from a module, VS Code can offer completions for other exports from that same file.
  • However, if you want to use symbols from another file (e.g. another process library within the same ADITO module) that you have not yet imported, VS Code cannot suggest them automatically.

In regular JS development this can be inconvenient: you often need to know or type many imports manually before IntelliSense becomes really helpful.

Solution: use declaration (.d.ts) files

To improve this, the devtools package offers a script that:

  1. Generates .d.ts types for your modules
    The createTypes script generates declaration files for the process and processes folders of your modules.
    These files can be committed to your Git repository and should be shipped with your published module so that consumers of your module automatically get the improved IntelliSense.

  2. Uses these .d.ts files in your JS configuration
    Together with the createJsconfig script, you can:

    • extend compilerOptions.paths to include your process/processes folders, and
    • write an include section that references all *.d.ts files provided by ADITO-specific modules.

A side effect of this setup is that Ctrl+Click navigation in VS Code will take you to the .d.ts file instead of the original .js file.
Because JSDoc is also exported to the .d.ts files, this is typically not an issue and still gives you full documentation. You can easily navigate from there to the underlying JS implementation if needed.

In summary, this approach allows you to get IntelliSense in VS Code even if you have not yet used a particular library in your current file.

Usage

1. Add the script to your package.json

If your project does not already define a createTypes script, add it under the scripts section:

"scripts": {
"Create types for your processes": "createTypes"
}

This script will create all necessary *.d.ts files for the process and processes folders of your module.

Also, it will create a jsconfig.types.json file that will be used for generating the declaration files. An extra jsconfig is necessary, because we do want other options than the default ones.

Empty declaration files will be removed after the script has finished.

2. Include .d.ts files in your published module

Adjust your package configuration (e.g. files section or .npmignore) so that the generated .d.ts files are included in the published module.
Consumers of your module will then get the improved IntelliSense out of the box.

This will be automatically done by the createJsconfig script.