Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Archives
Tags
- 자바
- mysql
- 자바 기초
- To Do List
- Break Continue
- react
- JS
- javascript
- Openjdk
- 로또 번호 생성
- db
- 웹디자인 기능사
- 전자정부프레임워크
- do while
- position
- 조건문
- 자바 환경변수
- vue
- CSS
- float
- HTML
- DropDown
- overflow
- 연산자
- Heidi
- java
- clear
- switch
- Display
- 자료형
- Today
- Total
잠온다
Typescript 설치 및 설정 본문
1. node.js 최신 버전 설치 https://nodejs.org/ko/
Node.js
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
nodejs.org
2. npm i -g typescript
에러 발생 시
1. node.js 삭제 후 최신 버전 설치
2. (윈도우) 허가되지 않은 script 실행 불가
: 시작 - 검색 - powershell - 우클릭 - 관리자 권한 실행 - Set - ExecutionPolicy Unrestricted - Y 선택
3. (맥북) sudo npm i -g typescript
3. tsc -w 명령어 실행 시 자동으로 js 파일로 변환함
React
1. 이미 있는 React 프로젝트에 설치할 경우
npm i --save typescript @types/node @types/react @types/react-dom @types/jest
2. React 프로젝트를 새로 만들 경우
npx create-react-app 작업폴더 --template typescript
환경설정
1. 프로젝트 폴더에 tsconfig.json 파일 생성
2. 기본 설정
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
}
}
3. 추가 설정
{
"compilerOptions": {
"target": "es5", // 'es3', 'es5', 'es2015', 'es2016', 'es2017','es2018', 'esnext' 가능
"module": "commonjs", //무슨 import 문법 쓸건지 'commonjs', 'amd', 'es2015', 'esnext'
"allowJs": true, // js 파일들 ts에서 import해서 쓸 수 있는지
"checkJs": true, // 일반 js 파일에서도 에러체크 여부
"jsx": "preserve", // tsx 파일을 jsx로 어떻게 컴파일할 것인지 'preserve', 'react-native', 'react'
"declaration": true, //컴파일시 .d.ts 파일도 자동으로 함께생성 (현재쓰는 모든 타입이 정의된 파일)
"outFile": "./", //모든 ts파일을 js파일 하나로 컴파일해줌 (module이 none, amd, system일 때만 가능)
"outDir": "./", //js파일 아웃풋 경로바꾸기
"rootDir": "./", //루트경로 바꾸기 (js 파일 아웃풋 경로에 영향줌)
"removeComments": true, //컴파일시 주석제거
"strict": true, //strict 관련, noimplicit 어쩌구 관련 모드 전부 켜기
"noImplicitAny": true, //any타입 금지 여부
"strictNullChecks": true, //null, undefined 타입에 이상한 짓 할시 에러내기
"strictFunctionTypes": true, //함수파라미터 타입체크 강하게
"strictPropertyInitialization": true, //class constructor 작성시 타입체크 강하게
"noImplicitThis": true, //this 키워드가 any 타입일 경우 에러내기
"alwaysStrict": true, //자바스크립트 "use strict" 모드 켜기
"noUnusedLocals": true, //쓰지않는 지역변수 있으면 에러내기
"noUnusedParameters": true, //쓰지않는 파라미터 있으면 에러내기
"noImplicitReturns": true, //함수에서 return 빼먹으면 에러내기
"noFallthroughCasesInSwitch": true, //switch문 이상하면 에러내기
}
}
'Typescript' 카테고리의 다른 글
TS) Typescript로 HTML 변경 및 조작할 때 주의점 (0) | 2022.05.30 |
---|---|
TS) Literal Types / as const (0) | 2022.05.28 |
TS) type alias / readonly / object 옵션 / type 키워드 합치기 (0) | 2022.05.28 |
TS) 함수 타입 지정 및 Type Narrowing (0) | 2022.05.28 |
TS) 기본 타입 및 union, any, unknown type (0) | 2022.05.28 |
Comments