타입스크립트 정리

타입스크립트 컨셉

const name = "hun", age = 28, gender = "male"; const sayHi = (name, age, gender?) => { // ?를 붙여주면서 있어도 되고 없어도 되게 한다 console.log(`Hello ${name} you are ${age}, you are a ${gender}`); }; sayHi(name, age); // 세번째 인자가 없는데 오류가 안뜨고 출력이 되지만 undefined로 출력됨. export {};

타입스크립트의 이점

  1. Types
  1. Next-gen JS Features(compiled down for older Browsers)
  1. Non-JS features(Interface, Generic)
  1. Meta-Programming features (Decorator)
  1. Rich Configuration Options
  1. Modern Tolling that helps even in non-TypeScript Project

컴파일러

tsc watchmode

tsc-watch 라이브러리가 없으면 node 환경으로 실행할때, package.json 의 script에 prestart에 tsc를 입력하고 이후에 start에 node 입력후 파일을 실행한다. 그리고, 매번 수정 될 때마다 실행해야되서 불편한다.
"tsc-watch" 라는 타입스크립트 라이브러리를 이용하자. (기존에 node.js의 nodemon과 비슷한 역할을 한다.)
package.json안의 script에
"start": "tsc-watch --onSuccess \" node 파일폴더/파일이름.js \""
그리고 tsconfig.json 에 compilerOption에 outDird에 "dist"를 추가하고 include 안을 "src/*/"로 바꿔준다.
{"compilerOptions": {"module": "commonjs","target":"ES2015","sourceMap":true, "outDir":"dist"},"include": ["src/**/*"], "exclude": ["node_modules"]}

interface

타입스크립트에서는 interface라고 js의 클래스와 같이 선언할수있다.
내 마음대로 선언하고 관리 할 수 있어서, 편하다.
자바스크립트의 class는 속성을 지정할수없지만, ts의 interface는 속성 모두를 지정 할 수 있다.
public과 private기능을 통해 권한(permission)을 정할 수 있다.
  • public
  • private

파일 소유자와 파일에 적용된 사용권한 확인

ls -l
  • 표현의 첫 시작인 -,d는 -는 not directory를 의미 하고 , d는 directory를 뜻한다.
  • r,w,x r: read , w:write , x:execute(실행) [permission]
  • 디렉토리/사용자/그룹/다른 순으로 쓰임

파일에 적용된 사용 권한 변경

chmod

rwx Absolute form

3bits 합 Read(r) : 4 Write(w) : 2 Execute(x) : 1

환경변수

Linux기반의 운영체제의 PC에는 전역변수를 설정할 수 있다.
시스템에 설정한 전역변수를 환경변수라고한다.