TypeScript?

수빈·2022년 3월 16일
0

TypeScript

목록 보기
1/7

⭐ TypeScript ?

= Language (Compiled,Transpile)
= Typed Superset of JavaScript
= compiles to plain JavaScript

*자바스크립트는 Interpreted Language이다.

CompiledInterpreted
컴파일, 컴파일러가 필요하다컴파일, 컴파일러가 필요없다.
컴파일하는 시점이 존재한다 = 컴파일 타임컴파일하는 시점이 존재하지 않는다.
컴파일된 결과물을 실행한다.코드 자체를 실행한다.
컴파일된 결과물을 실행하는 시점코드를 실행하는 시점 = 런타임

⭐ TypeScript는 Static Types로 JavaScript의 Dynamic Types와 달리 개발하는 중간에 type을 체크한다.

//JavaScript
function add(n1,n2){
if( typeof n1 !== "number" || typeof n2 !== "number") {
	throw new Error("Incorrent input!");
	}
  return n1 + n2;
}
const result = add(39,20);

//TypeScript
function add(n1:number, n2:number){ //Annotation을 통해 바로 알 수 있다.
	return n1 + n2;
}
const result = add (39,20);

⭐ structural type system

: 타입스크립트는 이름이 달라도, 구조가 같으면 같은 타입이다.

interface IPerson{
  name: string;
  age:number;
  speak():string;
}

type PersonType = {
  name: string;
  age:number;
  speak():string;
}

let personInterface : IPerson = {} as any;
let personType :PersonType = {} as any;

personInterface = personType;
personType = personInterface;

0개의 댓글

관련 채용 정보