tsconfig basics
- TypeScript course
- Beginner
- Lesson 4/89
- 4 min
Learn compiler options with tsconfig.json.
What is tsconfig.json?
tsconfig.json is the configuration file that specifies the TypeScript compiler's options. It defines which files to compile, the output folder, and the language target.
{
"compilerOptions": {
"target": "ES2020",
"outDir": "./dist"
}
}When this file is at the project root, tsc reads options from it.
The target option
target sets the version of the JavaScript that TypeScript produces. "ES5" produces code compatible with old browsers; "ES2020" keeps modern features.
{
"compilerOptions": {
"target": "ES5"
}
}A lower target means wider compatibility but a larger output.
Practice Two-parameter function
Write a function named hesapla. Its two parameters are a: number and b: number, its return type is number. Its body returns a + b. Then print the result of hesapla(10, 20) with console.log.
Starter code
// hesapla fonksiyonunu tanımla
// parametreler: a: number, b: number, dönüş: number
// hesapla(10, 20) sonucunu yazdırSample solution
function hesapla(a: number, b: number): number {
return a + b;
}
console.log(hesapla(10, 20));Expected output
30
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the role of tsconfig.json?
- Specifies compiler options Correct answer
- Lists package dependencies
- Defines test commands
- Configures Git settings
Explanation: tsconfig.json tells tsc which files to compile, the target JS version, and the output folder. The package list lives in package.json.
2 The target value
{
"compilerOptions": {
"target": "____"
}
}
{
"compilerOptions": {
"target": "ES2020"
}
}
Explanation: Valid target values are ES versions: ES5, ES2015, ES2020 and so on. JS2020, TS5 or V8 are not valid targets.
3 tsconfig parts
| Term | Meaning |
|---|---|
compilerOptions |
Compiler settings |
target |
JS version |
outDir |
Output folder |
tsconfig.json |
Configuration file |