๋ฐ˜์‘ํ˜•

๐Ÿ’™ Type Challenges 17

[TS] TypeScript Exercises 3 ํ•ด์„ ๋ฐ ํ’€์ด

Intro Since we already have some of the additional information about our users, it's a good idea to output it in a nice way. ์ด๋ฏธ ์œ ์ €์˜ ์ถ”๊ฐ€์ ์ธ ์ •๋ณด๋ฅผ ์•Œ๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, ๋ฉ‹์ง„ ๋ฐฉ๋ฒ•์œผ๋กœ ์ด๋ฅผ ํ‘œ์ถœํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค Exercise Fix type errors in logPerson function. logPerson function should accept both User and Admin and should output relevant information according to the input: occupation for User and role for Admin. logPerson ํ•จ์ˆ˜์˜ ํƒ€์ž…์—๋Ÿฌ..

[TS] type-challenges : 11. Tuple to Object

๋ฌธ์ œ ๋ฐฐ์—ด(ํŠœํ”Œ)์„ ๋ฐ›์•„, ๊ฐ ์›์†Œ์˜ ๊ฐ’์„ key/value๋กœ ๊ฐ–๋Š” ์˜ค๋ธŒ์ ํŠธ ํƒ€์ž…์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํƒ€์ž…์„ ๊ตฌํ˜„ํ•˜์„ธ์š”. ์˜ˆ์‹œ const tuple = ['tesla', 'model 3', 'model X', 'model Y'] as const type result = TupleToObject // expected { tesla: 'tesla', 'model 3': 'model 3', 'model X': 'model X', 'model Y': 'model Y'} ํ’€์ด ๊ฐ์ฒด์˜ ํ‚ค๋„, ๊ฐ’๋„ T๋ฐฐ์—ด์˜ ์š”์†Œ๊ธฐ ๋•Œ๋ฌธ์— ํ‚ค๊ฐ’ kv๊ฐ€ T[number]์— ์†ํ•ด์žˆ๊ณ  ์ด ๊ฒƒ์ด ํ‚ค์ธ ๋™์‹œ์— ๊ฐ’์ด๋ผ๊ณ  ๋ช…์‹œํ•ด์ฃผ๋ฉด ํ•ด๊ฒฐ๋œ๋‹ค. ์ด๋•Œ T๋Š” string ๋˜๋Š” number ๊ฐ€ ํฌํ•จ๋œ ๋ฐฐ์—ด์ด๋ผ๋Š” ์ ๋„ ๋ช…์‹œํ•ด์ค€๋‹ค. type TupleToObject..

[TS] TypeScript Exercises 2 ํ•ด์„ ๋ฐ ํ’€์ด

Introduce All 2 users liked the idea of the community. We should go forward and introduce some order. We are in Germany after all. Let's add a couple of admins. Initially, we only had users in the in-memory database. After introducing Admins, we need to fix the types so that everything works well together. ๋‘๋ช…์˜ ์œ ์ € ์ „๋ถ€ ์ปค๋ฎค๋‹ˆํ‹ฐ์˜ ์•„์ด๋””์–ด๊ฐ€ ๋งˆ์Œ์— ๋“ค์—ˆ๊ณ , ์šฐ๋ฆฌ๋Š” ์ด์ œ ์†Œ๊ฐœ๋ฅผ ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. admin ๋ช‡๋ช…์„ ์ถ”๊ฐ€ํ•ด๋ด…์‹œ๋‹ค. ์ฒ˜์Œ์— ์šฐ๋ฆฌ๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—๋งŒ ์œ ์ €๋ฅผ ์ €์žฅ..

[TS] TypeScript Exercises 1 ํ•ด์„ ๋ฐ ํ’€์ด

Introduce We are starting a small community of users. For performance reasons we have decided to store all users right in the code. This way we can provide our developers with more user-interaction opportunities. With user-related data, at least. All the GDPR-related issues will be solved some other day. This would be the basis for our future experiments during these exercises. ์šฐ๋ฆฌ๋Š” ์ด์ œ ์œ ์ €๋“ค์„ ์œ„ํ•œ ์ž‘์€..

[TS] type-challenges : 7. Readonly

๋ฌธ์ œ T์˜ ๋ชจ๋“  ํ”„๋กœํผํ‹ฐ๋ฅผ ์ฝ๊ธฐ ์ „์šฉ(์žฌํ• ๋‹น ๋ถˆ๊ฐ€)์œผ๋กœ ๋ฐ”๊พธ๋Š” ๋‚ด์žฅ ์ œ๋„ค๋ฆญ Readonly๋ฅผ ์ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๊ตฌํ˜„ํ•˜์„ธ์š”. ์˜ˆ์‹œ: interface Todo { title: string description: string } const todo: MyReadonly = { title: "Hey", description: "foobar" } todo.title = "Hello" // Error: cannot reassign a readonly property todo.description = "barFoo" // Error: cannot reassign a readonly property ํ’€์ด type MyReadonly = {readonly [key in keyof T]: T[key]} ์ถœ์ฒ˜ https..

[TS] type-challenges : 4. Pick

๋ฌธ์ œ T์—์„œ K ํ”„๋กœํผํ‹ฐ๋งŒ ์„ ํƒํ•ด ์ƒˆ๋กœ์šด ์˜ค๋ธŒ์ ํŠธ ํƒ€์ž…์„ ๋งŒ๋“œ๋Š” ๋‚ด์žฅ ์ œ๋„ค๋ฆญ Pick์„ ์ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๊ตฌํ˜„ํ•˜์„ธ์š”. ์˜ˆ์‹œ: interface Todo { title: string description: string completed: boolean } type TodoPreview = MyPick const todo: TodoPreview = { title: 'Clean room', completed: false, } ํ’€์ด type MyPick = {[key in K]: T[key]}; ์ถœ์ฒ˜ https://github.com/type-challenges/type-challenges/blob/main/questions/00004-easy-pick/README.ko.md GitHub - type-chal..

[TS] type-challenges : 13. Hello World

๋ฌธ์ œ Hello, World! Type Challenges์—์„œ๋Š” ํƒ€์ž… ๋‹จ์–ธ(assertion)์„ ํ•˜๊ธฐ ์œ„ํ•ด ์ž์ฒด์ ์ธ ํƒ€์ž… ์‹œ์Šคํ…œ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ณผ์ œ์—์„œ๋Š”, ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ๋ณ€๊ฒฝํ•ด์„œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ํ†ต๊ณผํ•˜์„ธ์š”. (ํƒ€์ž… ์ฒดํฌ ์—๋Ÿฌ ์—†์Œ). // string์ด ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. type HelloWorld = any // ์•„๋ž˜์˜ ํ…Œ์ŠคํŠธ๊ฐ€ ํ†ต๊ณผํ•˜๋„๋ก ๋งŒ๋“œ์„ธ์š”. type test = Expect Take the Challenge ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด์„œ ์ฝ”๋”ฉ์„ ์‹œ์ž‘ํ•˜์„ธ์š”! Happy Hacking! ํ’€์ด /* _____________ ์—ฌ๊ธฐ์— ์ฝ”๋“œ ์ž…๋ ฅ _____________ */ type HelloWorld = string // expected to be a string /* _____________ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ___..

๋ฐ˜์‘ํ˜•