개념 TypeScript javascript의 대체 언어이다. .ts 확장자를 사용하고 컴파일의 결과, .js 파일로 출력한다. 최종적으로 javascript 코드를 구동시키는 것 javascript 와 달리 타입을 명시 할 수 있어 코드 작성시 에러를 줄 일 수
타입의 종류 : 타입이란 자바스크립트에서 다루는 값의 형태에 대한 설명이다. (형태란, 값에 존재하는 속성과 메서드 그리고 내장되어 있는 typeof 연산자가 설명하는 것을 의미) - 일곱가지의 원시타입 null undefined boolean string number bigint symbol 타입 시스템 코드를 읽고 존재하는 모든 타입과 값을 이해한다...
유니언(Union) 값에 허용된 타입을 두 개 이상의 가능한 타입으로 확장하는 것 "이거 혹은 저거" 같은 타입을 Union 이라고 함 유니언을 선언한 모든 가능한 타입에 존재하는 멤버 속성에만 접근 할 수 있다. 내로잉(Narrowing) 값에 허용된 타입이 하나 이상의 가능한 타입이 되지 않도록 좁히는 것!! 타입을 좁히는데 사용할 수 있는 논리적 검...
객체 타입 {...} 구문을 사용해서 객체 리터럴을 생성 값의 속성에 접근하려면 value.멤버 | value['멤버'] 1.객체 타입 선언 별칭 객체 타입 구조적 타이핑 타입을 충족하는 모든 값을 해당 타입의 값으로 사용할 수 있다. 매개변수나 변수가 특정 객체 타입으로 선언되면 타입스크립트에 어떤 객체를 사용하든 해당 속성이 있어야 한다. 구조적...
함수 매개 변수 함슈으의 매개변수도 타입을 지정할 수 있다. 타입의 정보가 선언되지 않는다면 any타입으로 간주하며 매개변수의 타입은 무엇이든 될 수 있다. 필수 매개변수 함수에 선언되 모든 매개변수가 필수라고 가정하자. 함수가 잘못된 수의 인수로 호출되면, 타입스크
타입스크립트는 초기 배열에 데이터 타입이 있는지 기억하고, 배열이 해당 데이터 타입에서만 작동하도록 제한한다. (배열이 데이터 타입을 하나로 유지) 아래의 예제를 보면 string 타입 값 추가는 하용되지만 다른 데이터 타입 추가는 혀용되지 않는다. 배열 타입 배열을
타입별칭 vs. 인터페이스 debut: number와 namae: string을 가진 객체를 타입 별칭으로 구현하는 간락한 구문 인터페이스로 구현한 동일한 구문 => 위의 두 구분은 거의 같다. tip) 세미콜론(;)을 선호하는 타입스클비트 개발자는 대부분 인터페이스 뒤가 아닌 타입별창 뒤에 세미콜론을 넣는다. 이 기본 설정은 세미콜론을 사용해 변수를...