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
43 changes: 43 additions & 0 deletions 2week/assignment/01.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,46 @@ const person = {
country: 'ko',
sex: 'male',
};


type arr1 = ['a', 'b', 'c']
type arr2 = [1, 2, 3]

// type Arr<T extends any[]> = T;
// type First<T> = T extends Arr<infer A> ? A : any;

// type First<T extends unknown[]> = T[0] // ๊ฐ€๋Šฅ
// never[] <-- ์ง„์ •ํ•œ ๋นˆ ๋ฐฐ์—ด
// type First<T extends unknown[]> = T extends never[] ? never : T[0];
type First<T extends unknown[]> = T extends [infer F, ...unknown[]] ? F : never

type head1 = First<arr1>;
type head2 = First<arr2>;

type Last<T extends unknown[]> = T extends [...unknown[], infer L] ? L : never

type tail1 = Last<arr1>;
type tail2 = Last<arr2>;




type Fn<A extends number[]> = (...args:A) => any;
type FnArgs<T> = T extends Fn<infer A> ? A : any;

function test(name: number) {
// ๊ฐ’ ๊ณต๊ฐ„
return 3
}
type TestFn = FnArgs<typeof test>;


type StrFn = (input: string) => string;
const getSHA: StrFn = (input: string) => {
return input;
};

type PromiseFn<T> = T extends (...args: infer A) => infer R ? (...args: A) => Promise<R> : T;
const getSHAAsync: PromiseFn<StrFn> = (input: string) =>{
return new Promise((res) => input);
}
25 changes: 25 additions & 0 deletions 3week/assignment/01.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* ๋ฌธ์ œ1
* ๋‹ค์Œ์˜ ํŒŒํŒŒ๊ณ  ๋ฒˆ์—ญ api ๋ช…์„ธ๋ฅผ ํ™•์ธํ•˜๊ณ 
* ํŒŒ๋ผ๋ฏธํ„ฐ์— ํ•„์š”ํ•œ source ์™€ target ์„ ์ขํ˜€์ฃผ์„ธ์š”.
* @description: ๋งํฌ: https://developers.naver.com/docs/papago/papago-nmt-api-reference.md
* */

type SupportedLanguague =
|'ko'
|'en'
|'ja'
|'zh-CN'
|'zh-TW'
|'vi'
|'id'
|'th'
|'de'
|'ru'
|'es'
|'it'
|'fr';


type PapagoParamsSource = SupportedLanguague;
type PapagoParamsTarget = SupportedLanguague;
34 changes: 34 additions & 0 deletions 3week/assignment/02.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* ๋ฌธ์ œ2
* ์œ„์˜ PapagoParamsSource์™€ PapagoParamsTarget ๋ฅผ ์กฐํ•ฉํ•˜์—ฌ ๋ช…์„ธ์—์„œ ์–ธ๊ธ‰ํ•˜๋Š”
* "๋ฒˆ์—ญํ•  ์ˆ˜ ์žˆ๋Š” ์›๋ณธ ์–ธ์–ด์™€ ๋ชฉ์  ์–ธ์–ด๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค." ์˜ ์ œ์•ฝ์กฐ๊ฑด์„ ์ฐธ๊ณ ํ•˜์—ฌ PapagoParams ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ฐœ์„ ํ•ด ์ฃผ์„ธ์š”.
* */

interface KoParams {
source: 'ko';
target: SupportedLanguague;
text: string;
}
interface EnParams {
source: 'en';
target: 'ja'|'fr'|'zh-CN'|'zh-TW'|'ko';
text: string;
}
interface JaParams {
source: 'ja';
target: 'zh-CN' | 'zh-TW' | 'ko';
text: string;
}
interface ZhCnParams {
source: 'zh-Cn';
target: 'zh-TW';
text: string;
}

type PapagoParams = KoParams | EnParams | JaParams | ZhCnParams;

const params: PapagoParams= {
source: 'en',
target: 'ja',
text: 'Hello Typescript!'
}
40 changes: 40 additions & 0 deletions 3week/assignment/03.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* ๋ฌธ์ œ3
* ์Šคํƒ‘์›Œ์น˜ ๊ตฌํ˜„์„ ๋ณด๊ณ  ui ์ƒํƒœ interface ์„ค๊ณ„๋ฅผ ๊ฐœ์„ ํ•ด์ฃผ์„ธ์š”.
* https://online-stopwatch.ko.downloadastro.com/tools/
* */

// ์˜ˆ์‹œ ์ธํ„ฐํŽ˜์ด์Šค์ด๊ณ , ๋ณธ์ธ์ด ์ƒ๊ฐํ•˜๋Š” ๋” ๋‚˜์€ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ๋ฐ”๊พธ์…”๋„ ๋ฉ๋‹ˆ๋‹ค.
interface TimeInfo {
lappedTimeList?: string[];
timeFormStart: string;
timeFormLastLap: string;
}
interface ButtonStyle {
color: string;
icon: string
}

interface Initalized extends TimeInfo {
type: 'initialized';
startButton: ButtonStyle;
}
interface Running extends TimeInfo {
type: 'running';
pauseButton: ButtonStyle;
addLapButton: ButtonStyle;
}
interface Paused extends TimeInfo {
type: 'paused';
startButton: ButtonStyle;
resetButton: ButtonStyle;
}
type StopWatchState = Initalized | Running | Paused;

const initialState: StopWatchState = {
type: 'initialized',
startButton: { color: 'awf', icon: 'waef' },
timeFormStart: '0:00',
timeFormLastLap: '0:00',
lappedTimeList: []
}
76 changes: 76 additions & 0 deletions 3week/assignment/04.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* ๋ฌธ์ œ4
* ์š”๊ตฌ์‚ฌํ•ญ: naver๋‚˜ kakao ๋กœ๊ทธ์ธ(Oauth2.0)ํ•˜๊ธฐ ๊ธฐ๋Šฅ ์ด์šฉํ•ด
* ์œ ์ €์˜ ์ด๋ฆ„, ๋‹‰๋„ค์ž„, ํ”„๋กœํ•„ ์‚ฌ์ง„์„ ์–ป์–ด์™€ ์ถœ๋ ฅํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
*
* ์นด์นด์˜ค ์‚ฌ์šฉ์ž ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ api ๋ช…์„ธ์„ธ
* https://developers.kakao.com/docs/latest/ko/kakaologin/rest-api#req-user-info
* ์นด์นด์˜ค profile ๊ฐ์ฒด ์Šคํ‚ค๋งˆ
* https://developers.kakao.com/docs/latest/ko/kakaologin/rest-api#profile
*
* ๋„ค์ด๋ฒ„ ํ”„๋กœํ•„ API ํ˜ธ์ถœํ•˜๊ธฐ ๋ช…์„ธ
* https://developers.naver.com/docs/login/devguide/devguide.md#3-4-5-%EC%A0%91%EA%B7%BC-%ED%86%A0%ED%81%B0%EC%9D%84-%EC%9D%B4%EC%9A%A9%ED%95%98%EC%97%AC-%ED%94%84%EB%A1%9C%ED%95%84-api-%ED%98%B8%EC%B6%9C%ED%95%98%EA%B8%B0
*
* ์œ„์˜ ๋ช…์„ธ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํƒ€์ž…์„ ์ •์˜ํ–ˆ์Šต๋‹ˆ๋‹ค.
* */

interface KakaoUserProfile {
nickname: string;
profile_image_url: string;
}

interface KakaoUser {
name: string;
profile: KakaoUserProfile;
}

interface NaverUser {
nickname: string;
name: string;
profile_image: string;
}
interface UserInfo {
name: string;
nickname: string;
profileImage: string;
}

declare function getUser(userId: string): NaverUser | KakaoUser;

const isKakaoUser = (user: NaverUser | KakaoUser): user is KakaoUser => {
return 'profile' in user;
}

const getUserInfo = (userId: string): UserInfo => {
const userInfo: UserInfo = {
name: '',
nickname: '',
profileImage: '',
}
const response = getUser(userId);
if (isKakaoUser(response)) {
const { name, profile: { nickname, profile_image_url }} = response
userInfo.name = name;
userInfo.nickname = nickname;
userInfo.profileImage = profile_image_url;
} else {
const { nickname, name, profile_image } = response
userInfo.name = name;
userInfo.nickname = nickname;
userInfo.profileImage = profile_image;
}
return userInfo
}

// ๋‹ค์Œ ์˜ค๋ฅ˜๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ์œ„ํ•ด ํ•  ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  ๋Œ€์•ˆ์„ ์ ์šฉํ•ด์ฃผ์„ธ์š”.
function renderUserProfile(userId: string) {
const app = document.querySelector('#app')!;
const user = getUserInfo(userId);
app.innerHTML = `
<div>
<span>์ด๋ฆ„: ${user.name}</span>
<span>๋‹‰๋„ค์ž„: ${user.nickname}</span>
<img src="${user.profileImage}"></img>
</div>
`;
}
33 changes: 33 additions & 0 deletions 3week/assignment/05.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* ๋ฌธ์ œ5
* ํšŒ์›๊ฐ€์ž… form์„ ๋งŒ๋“ค์–ด์•ผํ•ฉ๋‹ˆ๋‹ค.
* ์•„์ด๋””, ๋น„๋ฐ€๋ฒˆํ˜ธ, ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ text input
* ์ถ”๊ฐ€ ์ •๋ณด์ž…๋ ฅ checkbox
* (์ถ”๊ฐ€์ •๋ณด์ž…๋ ฅ์„ ์ฒดํฌํ•˜๋ฉด)
* ์ฃผ์†Œ, ์ „ํ™”๋ฒˆํ˜ธ text input ์„ ๊ตฌํ˜„ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
* ํƒ€์ž…์„ ์ข€ ๋” ์ข๊ฒŒ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ฐœ์„ ํ•ด์ฃผ์„ธ์š”.
* */
interface AdditionalInfo {
address: string;
phone: string;
}

interface BaseData {
id: string;
password: string;
confirmPassword: string;
}
interface SignUpData extends BaseData {
additionalInfo?: AdditionalInfo
}

declare function postSignUpToV1(signupForm: SignUpData): void;
declare function postSignUpToV2(signupForm: SignUpData): void;

const sendSignup = (formData: SignUpData) => {
if (formData.additionalInfo) {
postSignUpToV2(formData);
} else {
postSignUpToV1(formData);
}
};