6장 타입스크립트 컴파일

타입스크립트가 웹에서 실행되려면 먼저 자바스크립트로 바뀌어야 한다. 이 장에서는 타입스크립트가 실행되는 전반적인 흐름을 살펴보고, 타입스크립트 컴파일러의 주요 역할과 구조에 대해 알아본다. 그리고 실제로 어떻게 컴파일하는지를 확인해본다.

6.1 자바스크립트의 런타임과 타입스크립트의 컴파일

6.1.1 런타임과 컴파일타임

6.1.2 자바스크립트 런타임

6.1.3 타입스크립트의 컴파일

6.2 타입스크립트 컴파일러의 동작

6.2.1 코드 검사기로서의 타입스크립트 컴파일러

6.2.2 코드 변환기로서의 타입스크립트 컴파일러

type Fruit = "banana" | "watermelon" | "orange" | "apple" | "kiwi" | "mango";
const fruitBox Fruit[] = ["banana", "apple", "mango"]
const welcome = (name: string) => {
  console.log(`hi! ${name} :)`);
}

"use strict";
var fruitBox = ["banana", "apple", "mango"];
var welcome = function (name) {
console.log("hi! ".concat(name, " :)"));
};
interface Square {
  width number;
}
interface Rectangle extends Square {
  height: number;
}

type Shape = Square | Rectangle;
function calculateArea(shape Shape) {
  if (shape instanceof Rectangle) {
    // 'Rectangle' only refers to a type, but is being used as a value here
    // Property 'height' does not exist on type 'Shape'
    // Property 'height' does not exist on type 'Square'
    return shape.width * shape.height;
  } else {
    return shape.width * shape.width;
  }
}

6.3 타입스크립트 컴파일러의 구조

6.3.1 프로그램

6.3.2 스캐너

6.3.3 파서

6.3.4 바인더

6.3.5 체커와 이미터

끝!