ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

TypeScript Tutorial• 6 min read

TypeScript Introduction & The Compiler (tsc)

Why static typing eliminates runtime bugs before your code reaches production

Created by Microsoft and Anders Hejlsberg (creator of C#), TypeScript is a typed superset of JavaScript that compiles down to clean, readable JavaScript compatible with any browser or runtime.

Why Enterprise Teams Choose TypeScript

Zero Runtime Cost: Types are stripped completely during compilation. There is zero runtime performance penalty.

Editor Intelligence: Autocomplete, instant refactoring, and inline documentation right in your IDE.

Catch Bugs Early: Catch typo bugs, null reference exceptions, and invalid argument shapes during development instead of in production.

Transpilation: tsc can down-compile modern ECMAScript features to older targets (ES5 or ES6) for legacy environment compatibility.

First TypeScript Program (index.ts)
interface Student {
  id: number;
  name: string;
  enrolled: boolean;
  score?: number; // Optional property
}

function calculateGrade(student: Student): string {
  if (student.score === undefined) {
    return 'Pending Evaluation';
  }
  return student.score >= 90 ? 'Grade A' : 'Passing';
}

const user: Student = {
  id: 101,
  name: "Marcus Aurelius",
  enrolled: true,
  score: 94
};

console.log(`Student: ${user.name} - ${calculateGrade(user)}`);
If you omit a required field or assign a string to id, the TypeScript compiler immediately throws an error.
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

What happens to TypeScript type annotations when code is compiled to JavaScript with tsc?