"Boldness has genius, power, and magic in it." - Johann Wolfgang von Goethe
728x90
728x90

type 4

[TS] TypeScript Type 별칭(Type Alias)

📘 타입 별칭 (Type Alias) Interface 랑 비슷해 보입니다. Primitive, Union Type, Tuple, Function 기타 직접 작성해야하는 타입을다른 이름을 지정할 수 있습니다. 만들어지 타입의 refer(별명)로 사용하는 것이지 타입을 만드는 것은 아닙니다. Aliasing Primitive type MyStringType = string; const str = 'world'; let myStr: MyStringType = 'hello'; // 같은 형식이기 때문에 같음 myStr = str; Aliasing Union Type let person: string | number = 0; person = 'Mark'; type St..

TypeScript 2021.09.02

[TS] TypeScript Basic Types 정리

기본 프로젝트 생성 후 아래 타입 실습! // package.json 생성 npm init -y // 개발용으로 TS 설치 npm i typescript -D // 프로젝트 루트경로에 tsconfig.json 파일이 생긴 것. npx tsc --init // tsconfig.json에서 이부분 확인하기. "strict": true, // JS로 컴파일 npx tsc // 파일 실행 noe [파일명] Boolean let isDone: boolean = false; isDone = true; console.log(typeof isDone) // boolean // 아래와 같이 리터럴로 직접 primitive타입을 사용하는 것이 일반적.. let isOk: Boolean = true; // 잘못된 사례 le..

TypeScript 2021.08.31

[TS] TypeScript 자료형_Primitive Types

📘 TypeScript와 JavaScript 비교 Static Types(ts) set during development function add(n1: number. n2:number) { return n1 + n2; } const result = add(39, 28); Dynamic Types(js) resolved at runtime function add(n1, n2) { if (typeof n1 !== 'number' || typeof n2 !== 'number') { throw new Error('Incorrect input!'); } return n1 + n2; } const result = add(39, 28); 프로그램이 유용하려면, 가장 간단한 데이터 단위로 작업 할 수 있어야 합니다. ..

TypeScript 2021.08.30

[TS] TypeScript _ VS CODE 설치 및 설정

📘 VS Code 설치 및 설정 Visual Studio Code TypeScript Compiler VS Code에 컴파일러가 내장되어 있다. 내장된 컴파일러 버전은 VS code가 업데이트 되면서 올라간다. 그래서 컴파일러 버전과 VS code의 버전은 상관관계가 있다. 내장된 컴파일러를 선택할 수 있고, 직접 설치한 컴파일러를 선택할 수 도 있다. npm init -y # 개발용 TS 설치 npm i typescript -D 📘 First Type Annotation TypeScript의 고유기능 Type이라는 요소가 프로그래밍에 들어남 // Type Annotation : 변수의 타입을 지정해줌. let a = 'Mark'; // a는 문자가 최초로 입력되었기 때문에 타입이 문자열로 지정됨. le..

TypeScript 2021.08.28
728x90
728x90