Typescript Watch mode!👀
tsc app.ts를 사용해서 .js 변환 후 사용하면 conflict 난다...
매번 바꿀떄마다 확인하기도 힘들고 ...
tsc app.ts -w
여러개의 파일을 comfile해야 할 떈?!
cd typescript-comfiler // 해당 파일로 이동
tsc --init // tsconfig.json 파일 생성
tsconfig.json 의 설명
typescript 를 위한 프로젝트 파일 표시기,
이 폴더에 있는 프로젝트와 모든 하위 폴더는 타입스크립트로 관리되고 있다.
tsc
=> .ts 로 생성된 파일들 전체를 .js로 변환해준다.(테스트 때 conflict 엄청 날거 같은데...)
tsconfig.json의 사용법
"exclude": ["node_modules"],
"inclued": ["analytics.ts"],
"files": ["files"]
- exclude : uncomfile 할 file 을 지정한다.
: exclude가 없다면 node_modules 파일은 default
- inclued : comfile 할 file 을 지정
: 없다면 전체~
- files : 해당 파일 안에 있는 .ts 파일 전체를 comfile~
등등...
es6와 Type Script
스프레드 연산자
배열 및 객체에 저장된 데이터를 검색하는 방법!const hobbies = ["sports", "cooking"]; const activeHobbies = ["Hiking"]; activeHobbies.push(...hobbies); console.log(activeHobbies); // (3) ['Hiking', 'sports', 'cooking']
배열은 객체이고 객체는 참조 값,
메모르는 변경되지만, 주소는 변경되지 않는다.
배열의 요소를 가져 올 때 사용한다.
const hobbies = ["sports", "cooking"]; const activeHobbies = ["Hiking"]; activeHibbies.push(hobbies); // >> error 중첩 배열 activeHibbies.push(hobbies[0], hobbies[1]); // >> error x (이렇게 가져오면 힘들어..) const activeHibbies = ["Hiking", ...hobbies]; // 좋은 방법!
rest parameters(스프레드 연산자)
메개변수를 유동적으로 사용할 수 있다.
const add = (...numbers: number[]) => {
return numbers.reduce((curResult, curValue) => {
return curResult + curValue;
}, 0);
};
const addNumbers = add(5, 3, 5, 67, 8);
console.log(addNumbers);
- 배열 및 객체 비구조화 할당
배열 디스트럭처링
const hobbies = ["sports", "cooking"];
const [hobbie1, hobbie2, ...remainningHibbies] = hobbies;
console.log(hobbies, hobbie1, hobbie2);
// (2) ['sports', 'cooking'] 'sports' 'cooking'
객체 비구조화 할당
const person = {
name: "cho",
age: 20,
};
const { name, age } = person;
console.log(name, age);
//cho 20
'Typescript' 카테고리의 다른 글
Union Type, Intersection Type, Etc...🙏(feat..optional chaining) (3) | 2024.09.11 |
---|---|
Class...🏫 (6) | 2024.09.10 |
처음 보는 typescript...😂 (0) | 2024.09.03 |