
TypeScript는 Typed JavaScript로 유형을 추가하고 Compile함으로써 코드 실행 전에 오류를 포착하여 개발 속도를 높이고 능률을 향상시킨다.
JavaScript를 기반으로 하는 오픈소스 프로그래밍 언어로 JavaScript가 시행되는 모든 환경에서 작동한다.
JavaScript는 동적 언어이나, TypeScript는 정적 언어이다.
따라서 컴파일을 통해 에러 캐치가 수월한 것이다.

JavaScript는 ==로 값을 비교하면 type을 고려하지 않고 결과를 추출한다.
그래서 ===와 같이 비교해줘야 올바른 비교가 가능하다.
const a = 0;
const b = "0";
console.log(typeof a); // typeof는 python의 type(a)와 같다.
console.log(typeof b);
console.log(a == b)
console.log(a === b)
// 출력 결과
number
string
true
false
그리고 Object 객체에 접근할 때, 해당 객체가 없는 경우 Error가 발생하면서 코드 구문이 멈추거나 undefined 값을 반환한다.
const man = {
name: "wontae",
age: 10,
};
console.log(man.name);
console.log(man.address);
// 출력결과
wontae
undefined
그래서 TypeScript가 등장하게 된다.
TypeScript는 해당 객체 유무에 따른 결과 등도 모두 interface를 선언하기 때문에 조기에 에러를 캐치할 수 있다.


let array: type[];let a: number;let a: string;let a: boolean;let employee: object;
employee = {
name: 'wontae',
age: 25,
}
console.log(employee)
let a = string[]; let b = number[];let human: [string, number]; human = ['wontae', 25];enum Month { Jan, Feb, ... }let result: any;function log(msg): void {
console.log(msg);
// 항상 오류 발생
function invalid(message:string): never {
throw new Error(message);
}
// never 타입을 결과 추론(Inferred)
function fail() {
return invalid('실패');
}
// 무한 루프
function infiniteAnimate(): never {
while ( true ) { infiniteAnimate(); }
}
Union
// number 혹은 string
function setInfo(id:number|string, name:string){
return { id, name };
}
Type type Human: 'Man' | 'Woman';
TypeScript는 개발자의 실수를 줄이고, 협업하기 적합하다.
숙달되기 위해 노력해보자.