Dream๐Ÿฐng
article thumbnail
[TS] Drag & Drop 2๏ธโƒฃ
๐Ÿ“ Study/TypeScript 2023. 3. 30. 01:33

๐Ÿ‘ 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์ด ๋งž๋Š”์ง€ ํ™•์ธํ•˜๋ ค๋ฉด ๋ฐฐ์—ด์ธ์ง€ ์—ฌ๋ถ€๋ฅผ ํ™•์ธ..

article thumbnail
[TS] Decorators 3๏ธโƒฃ
๐Ÿ“ Study/TypeScript 2023. 3. 24. 19:36

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..

article thumbnail
[TS] Decorators 2๏ธโƒฃ
๐Ÿ“ Study/TypeScript 2023. 3. 22. 11:56

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() {..

article thumbnail
[TS] Decorators 1๏ธโƒฃ
๐Ÿ“ Study/TypeScript 2023. 3. 20. 12:51

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..

profile on loading

Loading...