TypeScript Compiler Overview

Lesson Description
The "TypeScript Compiler Overview" Lesson is part of the full, TypeScript: From First Steps to Professional course featured in this preview video. Here's what you'd learn in this lesson:
Anjana discusses the process of compiling and highlights the TypeScript compiler's ability to generate JavaScript code from TypeScript source code. She also mentions exploring type inference, advanced type concepts like interfaces and generics, and configuring the compiler using tsconfig.json files.
Transcript from the "TypeScript Compiler Overview" Lesson
[00:00:00]
>> Anjana Vakil: Congratulations everyone You have written a TypeScript file and compiled it to JavaScript, which means you're a TypeScript developer, and now all we need to do is wrap our heads around the 8 billion possible things that we can tell the TypeScript compiler we want it to do, to transform our TypeScript into JavaScript So earlier we were talking about like, what is compiling mean What does it mean when we say TypeScript compiles to JavaScript
[00:00:32]
And we've just seen it in action So we ran tsc with the strict flag, but most importantly, we ran it on this TypeScript file, .ts, and that emitted or compiled to a JavaScript file which is not the same JavaScript file that we started with It is, as we can see by like, things that look sort of strange in here, this was automatically generated by the TypeScript compiler And so this is what we mean when we talk about compiling as like writing new sheet music
[00:01:17]
Now, we have something that's a .js file that the browser knows what to do with, that Node knows what to do with They all know how to read JavaScript sheet music Some of them, some of the fancier new experimental musicians of Node, are also able to start running .ts files directly, but as it stands right now, we still often need JavaScript to be running in the browser or especially like if somebody has an older environment
[00:01:50]
So we are going to dive into the TypeScript compiler a bit deeper and try to wrap our heads around how TypeScript is generating that JavaScript code from our original TypeScript source code So we want to understand a bit more like, how exactly does that compilation process work And we also noticed earlier that we saw we had some elements of type inference where the compiler knew stuff about types in our code that we hadn't explicitly told it
[00:02:28]
So we're going to figure out more how we can take better advantage of that and how TypeScript knows all that stuff about like the string filter method or so on and so forth Now, we already saw a few ways that we can take our little type building blocks and build bigger and bigger types like those type aliases We're going to start talking about even fancier types of types You might have heard, you might have seen the word interface around in your TypeScript repositories or you might have heard of generics or fancy jargon like that
[00:03:04]
We're going to talk about all that, and we are going to talk a lot about configuring the compiler, and you may have seen files called tsconfig.json out there in the wild We're going to talk about what those files are, what they do, how they work We are compiling TypeScript We are like masters of the universe We write type colon, blah blah, and then we compile magically to JavaScript that doesn't have that syntax, and we're going to figure out exactly how our wonderful magic works under the hood
[00:03:42]
Question Is this going to allow us to compile more than one TypeScript file I believe with a little bit of stick-to-itiveness and me making you do exercises, yes, we are going to be compiling more than one TypeScript file And there was a question earlier about, like, are there ways that we can understand Can we go backwards from the output JavaScript to the original TypeScript Are there like, are there other files that we can emit, and we're going to talk about all of that in this next part of the course.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops