From 91b94ce5d3bf020de08a5c323b1a8d335e40c979 Mon Sep 17 00:00:00 2001 From: Ezio Date: Sat, 7 Jan 2017 15:54:30 +0800 Subject: [PATCH] =?UTF-8?q?20170107-6=20=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20 TypeScript: the missing introduction.md | 406 ++++++++++++++++++ 1 file changed, 406 insertions(+) create mode 100644 sources/tech/20161220 TypeScript: the missing introduction.md diff --git a/sources/tech/20161220 TypeScript: the missing introduction.md b/sources/tech/20161220 TypeScript: the missing introduction.md new file mode 100644 index 0000000000..545d404c0f --- /dev/null +++ b/sources/tech/20161220 TypeScript: the missing introduction.md @@ -0,0 +1,406 @@ +TypeScript: the missing introduction +============================================================ + + +**The following is a guest post by James Henry ([@MrJamesHenry][8]). I am a member of the ESLint Core Team, and a TypeScript evangelist. I am working with Todd on [UltimateAngular][9] to bring you more award-winning Angular and TypeScript courses.** + +> The purpose of this article is to offer an introduction to how we can think about TypeScript, and its role in supercharging our **JavaScript** development.  +> +> We will also try and come up with our own reasonable definitions for a lot of the buzzwords surrounding types and compilation. + +There is huge amount of great stuff in the TypeScript project that we won’t be able to cover within the scope of this blog post. Please read the [official documentation][15] to learn more, and check out the [TypeScript courses over on UltimateAngular][16] to go from total beginner to TypeScript Pro! + +### [Table of contents][17] + +* [Background][10] +* [Getting to grips with the buzzwords][11] + * [JavaScript - interpreted or compiled?][1] + * [Run Time vs Compile Time][2] + * [The TypeScript Compiler][3] + * [Dynamic vs Static Typing][4] +* [TypeScript’s role in our JavaScript workflow][12] + * [Our source file is our document, TypeScript is our Spell Check][5] +* [TypeScript is a tool which enables other tools][13] + * [What is an Abstract Syntax Tree (AST)?][6] + * [Example: Renaming symbols in VS Code][7] +* [Summary][14] + +### [Background][18] + +TypeScript is an amazingly powerful tool, and really quite easy to get started with. + +It can, however, come across as more complex than it is, because it may simultaneously be introducing us to a whole host of technical concepts related to our JavaScript programs that we may not have considered before. + +Whenever we stray into the area of talking about types, compilers, etc. things can get really confusing, really fast. + +This article is designed as a “what you need to know” guide for a lot of these potentially confusing concepts, so that by the time you dive into the “Getting Started” style tutorials, you are feeling confident with the various themes and terminology that surround the topic. + +### [Getting to grips with the buzzwords][19] + +There is something about running our code in a web browser that makes us _feel_ differently about how it works. “It’s not compiled, right?”, “Well, I definitely know there aren’t any types…” + +Things get even more interesting when we consider that both of those statements are both correct and incorrect at the same time - depending on the context and how you define some of these concepts. + +As a first step, we are going to do exactly that! + +#### [JavaScript - interpreted or compiled?][20] + +Traditionally, developers will often think about a language being a “compiled language” when they are the ones responsible for compiling their own programs. + +> In basic terms, when we compile a program we are converting it from the form we wrote it in, to the form it actually gets run in. + +In a language like Golang, for example, you have a command line tool called `go build`which allows you to compile your `.go` file into a lower-level representation of the code, which can then be executed and run: + +``` +# We manually compile our .go file into something we can run +# using the command line tool "go build" +go build ultimate-angular.go +# ...then we execute it! +./ultimate-angular +``` + +As authors of JavaScript (ignoring our love of new-fangled build tools and module loaders for a moment), we don’t have such a fundamental compilation step in our workflow. + +We write some code, and load it up in a browser using a `