TypeScript | The School of Code

Settings

Appearance

Choose a typography theme that suits your style

TypeScript

Add type safety to your JavaScript code.

1

Hello TypeScript

TypeScript adds types to JavaScript, catching errors at compile time instead of runtime.

Example

Run this example to see how it works and then try the exercise.

example.ts
Loading...
Output
Click "Run" to see the example in action...
Exercise

Your task: Create a typed message variable and print it

main.ts
Loading...
Output
Click "Run" to execute your code...
Quiz

When does TypeScript catch type errors?

SUMMARY

In this section, you learned how to add type annotations to JavaScript. Next, you'll learn about basic types in TypeScript.

2

Basic Types

TypeScript has several basic types for primitive values.

Example

Run this example to see how it works and then try the exercise.

example.ts
Loading...
Output
Click "Run" to see the example in action...
Exercise

Your task: Declare typed variables: name (string), age (number), isStudent (boolean)

main.ts
Loading...
Output
Click "Run" to execute your code...
Quiz

What symbol is used to add a type annotation in TypeScript?

SUMMARY

In this section, you learned about basic types in TypeScript. Next, you'll learn how TypeScript infers types automatically.

3

Arithmetic Operations

TypeScript uses the same arithmetic operators as JavaScript, but with type safety to catch errors.

Example

Run this example to see how it works and then try the exercise.

example.ts
Loading...
Output
Click "Run" to see the example in action...
Exercise

Your task: Calculate area and print "Area: {area}"

main.ts
Loading...
Output
Click "Run" to execute your code...
Quiz

What type does TypeScript infer for let x = 10 + 5?

SUMMARY

In this section, you learned how TypeScript infers types automatically. Next, you'll learn how to perform arithmetic operations.

Unlock 10 More Lessons

You've completed the free preview! Upgrade to Pro to access all 12 lessons in this course, plus advanced projects and certificates.

Locked lessons:
  • String Operations
  • Conditionals
  • For Loops
  • While Loops
  • Functions
  • Arrays
  • Objects and Interfaces
  • Advanced Types
  • Final Project: Typed Task Manager
Hello TypeScript 1
Basic Types 2
Arithmetic Operations 3
Unlock 10 more lessons Access all content with Pro
Upgrade
String Operations 4 Conditionals 5 For Loops 6 While Loops 7 Functions 8 Arrays 9 Objects and Interfaces 10 Advanced Types 11 Final Project: Typed Task Manager 12

Reset Progress?

Are you sure you want to reset all progress for this course? This action cannot be undone.