Skip to content
Lesson 1 of 15

Step 1 of 5 · Reading · ~3 min

Learn

Getting Started

Hello, TypeScript

TypeScript is JavaScript with a static type system layered on top. Every valid JavaScript file is already valid TypeScript — you could rename app.js to app.ts and it would compile. What TypeScript adds is a compile-time checker: it reads your code, verifies that the types line up, and reports a whole class of bugs before the program ever runs.

Why does TypeScript exist?

Plain JavaScript happily accepts code like this:

const user = { name: "Alice" };
console.log(user.nmae.toUpperCase()); // typo — crashes at RUNTIME

In JavaScript you discover the nmae typo only when someone actually runs that line — maybe in production. TypeScript flags it the moment you write it, because it knows user has a name property and nothing called nmae.

That is the entire pitch: move bug discovery from runtime (expensive, public) to compile time (instant, private). The bonus is world-class tooling — autocomplete, go-to-definition, and safe renames all work because the editor knows the type of every value in your program.

Your first program

const greeting: string = "Hello, TypeScript!";
console.log(greeting);

Two things to notice:

  • : string is a type annotation. It declares "this variable holds a string." If you later try to assign a number to greeting, the compiler refuses.
  • console.log(...) prints its argument to standard output followed by a newline — exactly like JavaScript, because at runtime it IS JavaScript.

You do not have to annotate everything. TypeScript infers types: const greeting = "Hello" is already known to be a string without any annotation. When and where annotations pay off is the subject of the next lesson.

The trap: types vanish at runtime

The single most important mental model in TypeScript:

const greeting: string = "Hello, TypeScript!";

// After compilation, the emitted JavaScript is just:
// const greeting = "Hello, TypeScript!";

The compiler checks your annotations, then erases them. At runtime there are no types — no checks, no speed penalty, and no protection against bad data arriving from a network response or user input. TypeScript is a static analyzer, not a runtime bodyguard. Beginners often expect : string to throw an error if a number sneaks in while the program runs. It will not — the annotation no longer exists by then. Runtime validation is code you still have to write yourself.

Your exercise

Write a program that prints exactly:

Hello, TypeScript!

One console.log with a string literal is all it takes. The grader compares your output character by character, so the mistakes it will catch are:

  • Wrong capitalization — it is Hello, TypeScript! with a capital H, capital T, and capital S (not Typescript, not hello).
  • A missing comma after Hello, a missing space after the comma, or a forgotten ! at the end.
  • Extra output — print the greeting and nothing else.

console.log adds the trailing newline for you. (Whitespace at the very end of your output is trimmed before the comparison, so one extra newline will not fail you — but an extra printed LINE will.)

Up nextType AnnotationsGetting Started

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…