TypeScript가 필요한 이유 : 타입 안정성!

<aside> 🧑‍🌾 자바스크립트는 실행 후에나 오류를 알 수 있음 ( ← 동적언어) 타입스크립트는 컴파일시에 타입이 결정되며 오류를 발견함 (←정적언어)

</aside>

Untitled

이게 뭔소리?

  1. JS의 동일연산자(==)는 인수를 강제로 변환해 예기치 않은 동작을 유발함 (⇒ === 요거 쓰자~.~)

    암묵적 형변환 ! !

    ("" == 0) :빈문자열은 false false는 0 ~

    1<x<3: 1이랑 x 먼저 비교해… true(1) false(0)과 3이랑 비교해..

![Untitled](<https://prod-files-secure.s3.us-west-2.amazonaws.com/e8993e31-c1ee-4f1a-a471-5500b43b098b/729cd13e-94b2-4f00-9eda-80b48a19df81/Untitled.png>)

스크린샷 2024-03-19 오전 11.11.26.png

Untitled

tsconfig.json

tsconfig.json 파일 생성

tsc --init 

include & exclude

{
	"include": ["**/*.ts", "**/*.tsx"],  // .ts/tsx가 확장자인 파일은 모두컴파일 "src" 처럼 폴더를 지정하여 해당 폴더 안에 있는 모든 .ts 파일을 한번에 컴파일 
  "exclude": ["node_modules", "build", "dist", "**/*.(spec|test).ts"]
}

compilerOptions