Assess your understanding of tsconfig.json with questions covering its structure, compiler options, and common configuration scenarios. Perfect for those looking to enhance skills in TypeScript project setup and customization.
In a tsconfig.json file, what is the primary purpose of the 'compilerOptions' property?
Explanation: The 'compilerOptions' property is used to define various settings that determine how the TypeScript compiler processes and compiles your code, such as the target JavaScript version or module system. Option A is incorrect because linter rules are not specified here. Option B refers to file inclusion, which is configured by 'include' or 'files'. Option D mistakenly identifies documentation settings, which are not managed directly by 'compilerOptions'.
If you want to prevent the TypeScript compiler from including files in a 'temp' directory, which property should you use in tsconfig.json?
Explanation: The 'exclude' property allows developers to clearly specify patterns or directories that should be skipped by the compiler, such as 'temp'. 'exports' is not a valid tsconfig.json property for this purpose. 'extents' is a misspelling and does not exist, while 'expunge' is not a recognized property. Only 'exclude' achieves the intended behavior.
Suppose you want to share base settings among multiple tsconfig.json files; which property helps with this by referencing a base configuration?
Explanation: The 'extends' property lets a tsconfig.json file inherit configuration from another, helping maintain consistency across multiple projects. 'expand', 'explore', and 'extract' are similar-sounding, but none are actual tsconfig.json properties relevant to configuration sharing. Only 'extends' provides this form of inheritance.
What is the effect of setting the 'outDir' option in the 'compilerOptions' of tsconfig.json?
Explanation: 'outDir' sets the directory where the generated JavaScript files are output after compilation. Option A may seem plausible, but 'outDir' does not specifically target declaration files. Option C refers to exclusion, handled by 'exclude'. Option D describes type checking, which is not controlled by 'outDir' but by options like 'strict'.
If you omit both 'include' and 'files' in your tsconfig.json, which files does the TypeScript compiler attempt to compile by default?
Explanation: By default, the compiler searches for all .ts files in the current directory and its subdirectories, ignoring certain folders like 'node_modules' and anything listed in 'exclude'. The first option is too restrictive, only covering the top-level directory. Option C is incorrect as the compiler defaults to a broad search rather than none. Option D requires explicit file listing, which is not the default behavior.