(이펙티브 타입스크립트)
'타입스크립트는 자바스크립트의 상위호환superset 이다'
npm install -g typescript
컴파일? ts 파일을 js 로 변환 하는거였음
tsc main.ts
tsc를 돌리거나 ts 문법 체크 플러그인을 설치하면 상세한 문법사항을 지적해줌
interface State { name: string; capital: string; } const states: State[] = [ { name: "alabama", capital: "montgomery" }, { name: "alaska", capitol: "juneau" }, // ts 문법오류, js 오류 { name: "arizona", capital: "phoenix" }, ]; for (const state of states) { console.log(state.capital); }
엄격하게 문법 체크해줌
const x = 2 + "3"; // ts, js 정상 const y = "2" + 3; // ts, js 정상 const a = null + 7; // ts 문법오류, js 정상 const b = [] + 12; // ts 문법오류, js 정상 alert("hello", "typescript"); // ts 문법오류, js 정상 var names = ["alice", "bob"]; console.log(names[2].toUpperCase()); // ts 정상, 실행시 오류