tsconfig.json file, what will be the output when running tsc in the same directory?{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"outDir": "dist"
},
"include": ["src/**/*"]
}The target option sets the JavaScript version to ES5. The module option sets the module system to CommonJS. The outDir option specifies the output folder for compiled files, here 'dist'. The include option tells the compiler to include all files inside the 'src' folder.
tsconfig.json snippet. What error will the TypeScript compiler show?{
"compilerOptions": {
"target": "ES6",
"module": "amd",
"strict": true
},
"exclude": ["node_modules"]
}The strict option enables strict type checking and is valid. AMD modules are supported with ES6 target. The exclude option is valid and excludes 'node_modules' from compilation. So no error occurs.
tsconfig.json compiles without errors, but the output JavaScript throws an error at runtime. Why?{
"compilerOptions": {
"target": "ES5",
"module": "ESNext",
"lib": ["DOM", "ES2015"],
"outDir": "build"
},
"include": ["app/**/*"]
}When targeting ES5 but using ESNext modules, the output uses import/export syntax which ES5 environments do not support natively, causing runtime errors.
tsconfig.json:{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"allowJs": true,
"outFile": "dist/app.js",
"rootDir": "src",
"noEmitOnError": false
}
}The outFile option can only be used when the module system is set to 'none' or 'system'. It is invalid with 'commonjs' modules.
tsconfig.json and the project structure below, how many TypeScript files will be compiled?{
"compilerOptions": {
"target": "ES6",
"module": "commonjs"
},
"include": ["src/**/*.ts", "tests/**/*.ts"],
"exclude": ["src/legacy/**"]
}
Project structure:
- src/app.ts
- src/utils.ts
- src/legacy/old.ts
- tests/test1.ts
- tests/helpers/test2.ts
- README.mdThe include patterns select all .ts files in 'src' and 'tests' folders. The exclude pattern removes all files in 'src/legacy'. So 'src/app.ts', 'src/utils.ts', 'tests/test1.ts', and 'tests/helpers/test2.ts' are included. 'src/legacy/old.ts' is excluded. Total 4 files.