🔵 🔵 🔵


Primary

၊၊||၊|။

tsc ○›|Explanation|1st|20260718172102-00-⌔

TypeScript: Documentation - The Basics#tsc-the-typescript-compiler

tsc, the TypeScript compiler

We’ve been talking about type-checking, but we haven’t yet used our type- checker. Let’s get acquainted with our new friend tsc, the TypeScript compiler. First we’ll need to grab it via npm.

shnpm install -g typescript

This installs the TypeScript Compiler tsc globally. You can use npx or similar tools if you’d prefer to run tsc from a local node_modules package instead.

Now let’s move to an empty folder and try writing our first TypeScript program: hello.ts:

ts// Greets the world.console.log("Hello world!");Try

Notice there are no frills here; this “hello world” program looks identical to what you’d write for a “hello world” program in JavaScript. And now let’s type-check it by running the command tsc which was installed for us by the typescript package.

shtsc hello.ts

Tada!

Wait, “tada” what exactly? We ran tsc and nothing happened! Well, there were no type errors, so we didn’t get any output in our console since there was nothing to report.

But check again - we got some file output instead. If we look in our current directory, we’ll see a hello.js file next to hello.ts. That’s the output from our hello.ts file after tsc compiles or transforms it into a plain JavaScript file. And if we check the contents, we’ll see what TypeScript spits out after it processes a .ts file:

js// Greets the world.console.log("Hello world!");

In this case, there was very little for TypeScript to transform, so it looks identical to what we wrote. The compiler tries to emit clean readable code that looks like something a person would write. While that’s not always so easy, TypeScript indents consistently, is mindful of when our code spans across different lines of code, and tries to keep comments around.

What about if we did introduce a type-checking error? Let’s rewrite hello.ts:

ts// This is an industrial-grade general-purpose greeter function:function greet(person, date) {  console.log(`Hello ${person}, today is ${date}!`);} greet("Brendan");Try

If we run tsc hello.ts again, notice that we get an error on the command line!

txtExpected 2 arguments, but got 1.

TypeScript is telling us we forgot to pass an argument to the greet function, and rightfully so. So far we’ve only written standard JavaScript, and yet type-checking was still able to find problems with our code. Thanks TypeScript!

Printed 2026-07-18.

(echo:: @ )

Link to original

Secondary

• • •