Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
.env
64 changes: 64 additions & 0 deletions week01/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* ----------------------------------- 실습1 ---------------------------------- */

function info(name: string, age?: number): string {
if (age) {
return `안녕하세요, ${age}살 ${name}입니다.`;
} else {
return `안녕하세요, ${name}입니다`;
}
}

console.log(info('이펍'));
console.log(info('이펍', 20));

/* ----------------------------------- 실습2 ---------------------------------- */
function combine(input: string): string;
function combine(input: number): number;

function combine(input: string | number): string | number {
if (typeof input === 'string') {
return 'Hello,' + input;
} else {
return input * 2;
}
}

let result1 = combine('John');
console.log(result1);

let result2 = combine(5);
console.log(result2);

/* ----------------------------------- 실습3 ---------------------------------- */
interface Info {
(name?: string, age?: number): string;
}

const info2: Info = (name, age) => {
if (age) {
return `안녕하세요, ${age}살 ${name}입니다`;
} else {
return `안녕하세요, ${name}입니다`;
}
};

console.log(info2('이펍'));
console.log(info2('이펍', 20));

/* ----------------------------------- 실습4 ---------------------------------- */
interface Person {
name: string;
age: number;
}

interface Me extends Person {
school: string;
}

const me: Me = {
name: '이화',
age: 20,
school: 'Ewha',
};

console.log(me);
48 changes: 48 additions & 0 deletions week01/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions week01/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "week01",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"type": "commonjs",
"main": "index.js",
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
"watch": "tsc --watch",
"clean": "rm -rf dist",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"@types/node": "^24.3.1",
"typescript": "^5.9.2"
}
}
3 changes: 0 additions & 3 deletions week01/sample.md

This file was deleted.

64 changes: 64 additions & 0 deletions week01/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* ----------------------------------- 실습1 ---------------------------------- */

function info(name: string, age?: number): string {
if (age) {
return `안녕하세요, ${age}살 ${name}입니다.`;
} else {
return `안녕하세요, ${name}입니다`;
}
}

console.log(info('이펍'));
console.log(info('이펍', 20));

/* ----------------------------------- 실습2 ---------------------------------- */
function combine(input: string): string;
function combine(input: number): number;

function combine(input: string | number): string | number {
if (typeof input === 'string') {
return 'Hello,' + input;
} else {
return input * 2;
}
}

let result1 = combine('John');
console.log(result1);

let result2 = combine(5);
console.log(result2);

/* ----------------------------------- 실습3 ---------------------------------- */
interface Info {
(name?: string, age?: number): string;
}

const info2: Info = (name, age) => {
if (age) {
return `안녕하세요, ${age}살 ${name}입니다`;
} else {
return `안녕하세요, ${name}입니다`;
}
};

console.log(info2('이펍'));
console.log(info2('이펍', 20));

/* ----------------------------------- 실습4 ---------------------------------- */
interface Person {
name: string;
age: number;
}

interface Me extends Person {
school: string;
}

const me: Me = {
name: '이화',
age: 20,
school: 'Ewha',
};

console.log(me);
46 changes: 46 additions & 0 deletions week01/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
// Visit https://aka.ms/tsconfig to read more about this file
"compilerOptions": {
// File Layout
"rootDir": "src",
"outDir": "dist",

// Environment Settings
// See also https://aka.ms/tsconfig/module
"module": "commonjs",
"target": "esnext",
"types": [],
// For nodejs:
// "lib": ["esnext"],
// "types": ["node"],
// and npm install -D @types/node

// Other Outputs
// "sourceMap": true,
// "declaration": true,
// "declarationMap": true,

// Stricter Typechecking Options
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,

// Style Options
// "noImplicitReturns": true,
// "noImplicitOverride": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
// "noFallthroughCasesInSwitch": true,
// "noPropertyAccessFromIndexSignature": true,

// Recommended Options
"esModuleInterop": true,
"strict": true,
"jsx": "react-jsx",
"verbatimModuleSyntax": true,
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"moduleDetection": "force",
"skipLibCheck": true
},
"include": ["src"]
}
81 changes: 81 additions & 0 deletions week02/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* ---------------------------------- 실습 1 ---------------------------------- */
class Developer {
name: string; // 어디서든 접근 가능한 접근 제어자 설정
age: number; // 클래스 내부와 파생 클래스에서 접근 가능한 접근 제어자
position: string; // 클래스 내부에서만 접근 가능한 접근 제어자 설정
constructor(name: string, age: number, position: string) {
this.name = name;
this.age = age;
this.position = position;
}

sayHi() {
console.log(
`저는 ${this.age}살이고 이름은 ${this.name}입니다. 포지션은
${this.position}입니다`
);
}
}

class FrontendDeveloper extends Developer {
protected react: boolean;

constructor(name: string, age: number, position: string, react: boolean) {
super(name, age, position);
this.react = react;
}
}
// Developer 클래스를 상속받는 FrontendDeveloper 클래스를 선언해주세요
// 규칙 1. FrontendDeveloper 클래스에 'react'라는 이름의 새로운 필드를 선
// 언해주세요.
// (해당 필드의 접근 제어자는 protected, 타입은 boolean으로 설정)
// 규칙 2. 오류가 나지 않도록 constructor를 작성해주세요.(주의: super를 잊
// 지 마세요!)

/* ---------------------------------- 실습 2 ---------------------------------- */
class Developer1 {
constructor(
public name: string,
protected age: number,
private position: string
) {}

sayHi() {
console.log(
`저는 ${this.age}살이고 이름은 ${this.name}입니다. 포지션은
${this.position}입니다`
);
}
}

/* ----------------------------------- 실습3 ---------------------------------- */
function forEach<T, U>(arr: T[], callback: (item: T) => void) {
// forEach는 반환값이 없으므로 void
for (let i = 0; i < arr.length; i++) {
callback(arr[i]); // 배열의 모든 요소에 콜백함수를 한번씩 수행
}
}

/* ---------------------------------- 실습 4 ---------------------------------- */
interface Student {
type: 'student';
school: string;
}
interface Developer {
type: 'developer';
skill: string;
}
//User 인터페이스를 제네릭 인터페이스로 업그레이드 해주세요.(제네릭 타입은 T로 설정해주세요.)
interface User<T> {
name: string;
profile: T;
}
//제네릭을 이용해 매개변수 타입을 나타내어 불필요한 타일 좁히기를 없애주세요
function goToSchool(user: User<Student>) {
if (user.profile.type !== 'student') {
console.log('잘 못 오셨습니다');
return;
}
const school = user.profile.school;
console.log(`${school}로 등교 완료`);
}
26 changes: 26 additions & 0 deletions week03/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions week03/sample.md

This file was deleted.

Loading