Integration compiler options
There are a few compiler options that we can configure in order to help with the integration of JavaScript and TypeScript. These options will allow us to include JavaScript files within the same project as TypeScript files, as well as allowing us to do some type checking on JavaScript files. We are also able to generate declaration files from our TypeScript code, if we are building libraries for general consumption. In this section of the chapter, we will explore these compiler options.
The allowJs and outDir options
The default TypeScript compilation configuration, as seen in the tsconfig.json
file, will generate JavaScript files in the same directory as the source TypeScript files. The outDir
compilation option is used to specify a different output directory for the generated JavaScript, as follows:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
...