TypeScript - Bundling types
When you are using TypeScript inside projects that create a standalone web application, you do not need to think much about the compilation process, as it is likely handled by some out-of-the-box tools (NextJS, CRA, etc.). However, when you are trying to create a publishable library that will be used in other apps, the bundling options are crucial to understand.
Running tsc
locally will compile the closest project defined by a tsconfig.json. This tool can be used to compile simple TypeScript libraries, and the outcome will be determined by the configuration.
Other compilers also take into consideration the configuration that is set for the TypeScript compiler. Webpack and Rollup will use it to transpile .ts(x) files into their final form.
You will need to understand the most important options to have full control over the output. This is essential for optimizations and proper compatibility.
JavaScript standard compatibility
I know that I can specify the compatibility of the type system with different node environments using the module, moduleResolution, and lib options
I'm aware that I can adjust the output JavaScript syntax format with the target field
JSX
I know I can adjust the handling of JSX syntax within the JSX option
Bundling
I know that I can control what will be included in the final bundle and where the specific parts will be placed
I use declaration, declarationDir, and emitDeclarationOnly to handle types output. I use out / outDir / outFile to manage JavaScript output
I'm aware that options like isolatedModules can impact the structure of the code's outcome
I know that I can specify the compatibility of the type system with different node environments using the module, moduleResolution, and lib options
I'm aware that I can adjust the output JavaScript syntax format with the target field
I know that I can control what will be included in the final bundle and where the specific parts will be placed
I use declaration, declarationDir, and emitDeclarationOnly to handle types output. I use out / outDir / outFile to manage JavaScript output
I'm aware that options like isolatedModules can impact the structure of the code's outcome