Primary
tsc ○›|Explanation|1st|20260718172102-00-⌔
TypeScript: Documentation - The Basics#tsc-the-typescript-compiler
tsc, the TypeScript compilerWe’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 typescriptThis installs the TypeScript Compiler
tscglobally. You can usenpxor similar tools if you’d prefer to runtscfrom a localnode_modulespackage 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!");TryNotice 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
tscwhich was installed for us by thetypescriptpackage.shtsc hello.tsTada!
Wait, “tada” what exactly? We ran
tscand 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.jsfile next tohello.ts. That’s the output from ourhello.tsfile aftertsccompiles 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.tsfile: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");TryIf we run
tsc hello.tsagain, 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
greetfunction, 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
• • •