자바스크립트는 동적언어다.
즉, 런타임(실행될 때)에 타입이 결정되며 오류를 발견한다.
그러나 타입스크립트는 정적언어다.
즉, 컴파일(컴퓨터 또는 다른 언어가 읽을 수 있는 언어로 변환) 될 때 타입이 결정되며 오류를 발견한다.
0. 타입스크립트
typescript 란 다이나믹하게 이래도되고 저래도되는 망나니 javascript를 엄격하게 관리하는 일종의 에디터다.
모든 데이터의 타입을 정하여 타입 언매치로 발생하는 오류나 예상밖의 결과값을 예방할 수 있다.
1. node.js 설치
Node.js
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
nodejs.org
2. vscode 설치
https://code.visualstudio.com/
Visual Studio Code - Code Editing. Redefined
Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.
code.visualstudio.com
3. 터미널에서 타입스크립트 설치
npm i -g typescript
📌 용어 정리
1) npm : Node Package Manager (자바스크립트의 런타임 환경인 node.js의 패키지를 관리자)
2) i : install 의 약자
3) -g : 글로벌 설치 (전역 설치)
4. 주의사항
1) js 파일이 아닌 ts 파일에 작성한다.
2) 웹 브라우저는 ts 파일을 읽지 못하니 꼭 js 파일로 변환해줘야한다.
* 터미널에 아래 명령어 입력시 자동으로 변환
tsc -w
* -w : watch 의 약자
3) ts 사용시 꼭 tsconfig.json 파일을 생성하고 그 안에 ts에서 js로 컴파일시 옵션을 작성해줘야 한다.
5. 필수 문법 맛보기
함수에서 리턴 값 없이 그냥 기능만 있다면 func():void //이렇게 보이드로 설정하면 됨.
6. 간단하게 실습할 수 있는 곳
https://www.typescriptlang.org/
JavaScript With Syntax For Types.
TypeScript extends JavaScript by adding types to the language. TypeScript speeds up your development experience by catching errors and providing fixes before you even run your code.
www.typescriptlang.org
'html,css,js' 카테고리의 다른 글
[javascript] input에서 입력값 유무는 trim().length 로 확인하자 (0) | 2023.06.26 |
---|---|
[타입스크립트] 제네릭 Generics (0) | 2023.06.19 |
[html] 배열 filter 메서드 필터 사용법 (0) | 2023.05.30 |
[html, css, js] 앞으로 덮어쓰는 캐러셀 슬라이더 만들기 (feat. z-index) (0) | 2023.05.25 |
[html, css, js] 초간단 자동 슬라이드 (캐러셀) 만들기 (0) | 2023.05.24 |