코딩/TypeScript 4

utility

interface IProfile { name: string; age: number; school: string; hobby?: string; } // 아래 type들에 마우스 올려보면 어떻게 변경되었는지 확인 가능!! // 1. Partial 타입 => 내용 전부 ?타입(있어도 되고 없어도 되고) 만듦 type aaa = Partial; // 2. Required 타입 => 내용 전부 있어야 되는걸로 만듦 type bbb = Required; // 3. Pick 타입 => 필요한것만 가져다 만듦 type ccc = Pick; // 4. Omit 타입 => 필요없는것 제외해서 만듦 type ddd = Omit; // 5. Record 타입 type eee = "철수" | "영희" | "훈이"; // Un..

코딩/TypeScript 2024.03.17

gerneric

// 1. 문자/숫자/불린 기본타입 const getPrimitive = (arg1: string, arg2: number, arg3: boolean): [boolean, number, string] => { return [arg3, arg2, arg1]; }; const result1 = getPrimitive("철수", 123, true); // // // 2. any 타입(그냥 자바스크립트랑 같음) const getAny = (arg1: any, arg2: any, arg3: any): [any, any, any] => { console.log(arg1 + 100); // any는 아무거나 다 됨! return [arg3, arg2, arg1]; }; const result2 = getAny("철수..

코딩/TypeScript 2024.03.17

tsconfig.json

++ npx tsc --init 으로 자동생성 가능 typescript인 ts는 node에서 인식을 못하기 때문에 js로 바꿔줘야한다. 그 설정을 tsconfig.json이라는 파일을 만들고 아래 코드를 적어주는걸로 한다. { "compilerOptions": { "target": "es2015", "module": "commonjs", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true }, "$schema": "https://json.schemastore.org/tsconfig", "display": "Recommended" } 아래는 코드 내용 간단한 설명 { "co..

코딩/TypeScript 2024.03.16