
๐ Drag & Drop 2๏ธโฃ Tuple is an array tuple์ JavaScript์๋ ์๊ณ TypeScript์๋ง ์๋ ํ์ ์ด๋ค. ๋ฐ๋ผ์ ํน์ ๋ณ์๋ฅผ tuple ํ์ ์ผ๋ก ์ง์ ํ์ ๋, ์๋์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก tuple ํ์ ์์ ํ์ธํ ์ ์๋ค. const engineer: [string, string, string] = ['Apeach', 'Ogu', 'Choonsik']; engineer instanceof Tuple; // โ typeof engineer === 'tuple'; // โ (false) But tuple์ TypeScript์๋ง ์กด์ฌํ๋ ํ์ ์ด์ง๋ง JavaScript๋ก ์๊ฐํด๋ดค์ ๋ ๊ฒฐ๊ตญ์ ๋ฐฐ์ด์ด๋ค. ๊ทธ๋ฌ๋ฏ๋ก ์ ์ธํ ๋ณ์๊ฐ tuple์ด ๋ง๋์ง ํ์ธํ๋ ค๋ฉด ๋ฐฐ์ด์ธ์ง ์ฌ๋ถ๋ฅผ ํ์ธ..

Project Drag & Drop 1๏ธโฃ ! & as TypeScript์์ DOM ์กฐ์ํ ๋ ์ค๋ฅ ํด๊ฒฐํ๊ธฐ class ProjectInput { templateElement: HTMLTemplateElement; hostElement: HTMLDivElement; constructor() { this.templateElement = document.getElementById( 'project-input' )! as HTMLTemplateElement; this.hostElement = document.getElementById('app')! as HTMLDivElement; } } document.getElementById('id');์์ !๋ฅผ ์ถ๊ฐํ๋ ์ด์ ๋ TypeScript๊ฐ ์ด๊ฒ์ด null์ผ์..

Decorators 3๏ธโฃ Validation decorator ํ๋กํผํฐ ๋ฐ์ฝ๋ ์ดํฐ ์์ class Course { title: string; price: number; constructor(t: string, p: number) { this.title = t; this.price = p; } } const courseForm = document.querySelector('form')!; courseForm.addEventListener('submit', event => { event.preventDefault(); const titleEl = document.getElementById('title') as HTMLInputElement; const priceEl = document.getElementB..

Decorators 2๏ธโฃ Decorator the synthetic sugar ํด๋์ค ๋ฐ์ฝ๋ ์ดํฐ๋ constructor๋ฅผ ๋ฐํํ๋ฉด์ ๊ธฐ์กด constructor๋ฅผ ํ์ฅํ ์ ์๋ค. constructor๋ฅผ ํ์ฅํ ๋ super();๋ ๊ธฐ์กด ํด๋์ค ํ์ฅ์์์ ๋ง์ฐฌ๊ฐ์ง๋ก ๊ธฐ์กด ํด๋์ค์ ์ ๋ณด๋ฅผ ๊ธฐ์ตํ๊ณ ์ถ์ ๋ ์ฌ์ฉํ๋ฉด ๋๋ค. function ClassDeco() { return function(target: T) { return class extends target { constructor(..._: any[]) { super(); // not necessary /* write your code */ } } } } @ClassDeco class Person { name = 'Shou'; get name() {..

Decorators 1๏ธโฃ What is Decorators? ํด๋์ค, ํ๋กํผํฐ, ์ก์ธ์, ๋ฉ์๋, ํ๋ผ๋ฏธํฐ์ ์ฒจ๋ถํ ์ ์๋ ํน๋ณํ ํจ์์ด๋ค. ๋ฐ์ฝ๋ ์ดํฐ๊ฐ ๋ถ์ ํด๋์ค ๋ฑ๋ฑ ์์๋ ๋ฐ์ฝ๋ ์ดํฐ์์ ์ ์๋ ๊ธฐ๋ฅ์ด ๋์ํ๋ค. ์ ์ํ ๋ฐ์ฝ๋ ์ดํฐ ํจ์๋ฅผ @ ๊ธฐํธ๋ฅผ ๋ถ์ฌ ์คํํ ์ ์๋ค. function ClassDeco(constructor: Function) { console.log('Logging...'); console.log(constructor); } @ClassDeco class Person { name = 'Shou'; constructor() { console.log('Creating person object...'); } } /* Logging... class Person { constructo..

Generics 2๏ธโฃ Keyof Constraint ์ ๋ค๋ฆญ์ผ๋ก ๊ฐ์ฒด์ ๋ํ ์ ์ฝ ์กฐ๊ฑด์ ์ค ๋, ํค ๊ฐ์ ํ์๋ก ํ๋ค๋ฉด keyof๋ฅผ ์ฌ์ฉํ ์ ์ฝ ์กฐ๊ฑด์ ์ฐ๋ฉด ์ค์๋ฅผ ๋ฐฉ์งํ ์ ์๋ค. function extractAndConvert( obj: T, key: U ) { return 'Value: ' + obj[key]; } extractAndConvert({}, 'name'); // Error occurred ์ ๋ค๋ฆญ T์ ์ ์ฝ ์กฐ๊ฑด์ผ๋ก object๋ฅผ ์ค์ ํด์ฃผ์๊ณ , U์ ์ ์ฝ ์กฐ๊ฑด์ผ๋ก T์ key๋ฅผ ์ค์ ํด์ฃผ์๋ค. extractAndConvert๋ก ๋น ๊ฐ์ฒด({})์ name์ด๋ผ๋ ๋ฌธ์์ด์ ์ ๋ฌํ์ ๋, ๋น ๊ฐ์ฒด์๋ name์ด๋ผ๋ ํค ๊ฐ์ด ์๊ธฐ ๋๋ฌธ์ ์ปดํ์ผ ์ค๋ฅ๊ฐ ๋๋ค! ์ ๋ค๋ฆญ์ผ๋ก U extends keyof..

Generics 1๏ธโฃ What is Generics? ์ ๋ค๋ฆญ์ vanilla JavaScript์๋ ์๊ณ TypeScript์๋ง ์๋ ๊ฐ๋ ์ผ๋ก, ํน์ ํ์ ์ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ์ฌ ํ์ ์์ ์ฑ์ ํ๋ณดํ ์ ์๋ ๊ธฐ๋ฒ์ด๋ค. TypeScript์์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณตํ๋ ์ ๋ค๋ฆญ ํ์ ์ผ๋ก๋ Array, Promise๊ฐ ์๋ค. // Array const names: Array = []; /* Array์ ๋ํ ํ์ ์ string์ผ๋ก ์ง์ ํ๋ฉด(= Generic) ์์ผ๋ก names ๋ฐฐ์ด์ ๋ค์ด์ฌ ๋ฐ์ดํฐ์ ํ์ ์ด string์์ ์ถ๋ก ํจ */ // Promise const promise: Promise = new Promise((resolve, reject) => { setTimeout(() => { resolve(10); ..