CodeBlanks Logo Icon CodeBlanks

Summary - TypeScript basics

Write your first TypeScript program by combining setup, tsc, and tsconfig.

Summary - TypeScript basics

TypeScript is a typed superset of JavaScript. The tsc compiler turns .ts files into .js while checking types. With tsconfig.json you set the compile options and the target JS version.

// app.ts
let mesaj: string = "Merhaba TypeScript";
console.log(mesaj);
// Compile: tsc app.ts
// Run: node app.js

This way you write a safe program that catches errors early.

Practice Your first TypeScript program

Declare a variable ad with type string and value "TS". Declare a variable selam with type string and value "Öğreniyorum ". Then print the concatenation selam + ad with console.log.

Starter code

index.ts
// ad değişkeni: string, değer "TS"
// selam değişkeni: string, değer "Öğreniyorum "

// selam + ad birleşimini yazdır

Sample solution

index.ts
let ad: string = "TS";
let selam: string = "Öğreniyorum ";
console.log(selam + ad);

Expected output

Öğreniyorum TS

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which file specifies the compiler options in a TypeScript project?

  • package.json
  • README.md
  • tsconfig.json Correct answer
  • .gitignore

Explanation: tsconfig.json tells tsc the target JS version, the output folder, and which files to compile. package.json lists package dependencies.

2 Type annotation

Question
let mesaj: ____ = "Merhaba TypeScript";
Answer
let mesaj: string = "Merhaba TypeScript";

Explanation: "Merhaba TypeScript" is a string; so the type must be string. Assigning number or boolean gives a compile error.

3 TypeScript core parts

Term Meaning
tsc Compiler
tsconfig.json Configuration
.ts Source extension
target JS version

All lessons in Beginner