๋ฐ˜์‘ํ˜•

๐Ÿ’™ Typescript 17

[Typescript] TypeHero : Beginner ๋ฌธ์ œ ํ’€์ด

Generic Type Constraints https://typehero.dev/challenge/generic-type-constraints type AllowString = T; type AllowNumber = T; type CreateLogger void> = { log: T; exit: () => void; }; Index Signatures https://typehero.dev/challenge/index-signatures type GroceryList = {[item: string]: number}; type InappropriateActionBySituation = {[action: string]: Array}; type CharactersById = {[id: number]: {[pr..

[TS] type-challenges: 268 - If

๋ฌธ์ œ ์กฐ๊ฑด `C`, ์ฐธ์ผ ๋•Œ ๋ฐ˜ํ™˜ํ•˜๋Š” ํƒ€์ž… `T`, ๊ฑฐ์ง“์ผ ๋•Œ ๋ฐ˜ํ™˜ํ•˜๋Š” ํƒ€์ž… `F`๋ฅผ ๋ฐ›๋Š” ํƒ€์ž… `If`๋ฅผ ๊ตฌํ˜„ํ•˜์„ธ์š”. `C`๋Š” `true` ๋˜๋Š” `false`์ด๊ณ , `T`์™€ `F`๋Š” ์•„๋ฌด ํƒ€์ž…์ž…๋‹ˆ๋‹ค. ์˜ˆ์‹œ: type A = If // expected to be 'a' type B = If // expected to be 'b' ํ’€์ด type If = C extends true ? T : F type์—์„œ extends๊ฐ€ ๋“ฑํ˜ธ ๋‘๊ฐœ == ์— ํ•ด๋‹นํ•œ๋‹ค๊ณ  ๋ณด๋ฉด ํŽธํ•  ๊ฒƒ ๊ฐ™๋‹ค ์ถœ์ฒ˜ https://github.com/type-challenges/type-challenges/blob/main/questions/00268-easy-if/README.ko.md

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

Intro Filtering was completely removed from the project. It turned out that this feature was just not needed for the end-user and we spent a lot of time just because our office manager told us to do so. Next time we should instead listen to the product management. Anyway we have a new plan. CEO's friend Nick told us that if we randomly swap user names from time to time in the community, it would..

[TS] type-challenges: 189 - Awaited

๋ฌธ์ œ Promise์™€ ๊ฐ™์€ ํƒ€์ž…์— ๊ฐ์‹ธ์ธ ํƒ€์ž…์ด ์žˆ์„ ๋•Œ, ์•ˆ์— ๊ฐ์‹ธ์ธ ํƒ€์ž…์ด ๋ฌด์—‡์ธ์ง€ ์–ด๋–ป๊ฒŒ ์•Œ ์ˆ˜ ์žˆ์„๊นŒ์š”? ์˜ˆ์‹œ: ๋“ค์–ด Promise์ด ์žˆ์„ ๋•Œ, ExampleType์„ ์–ด๋–ป๊ฒŒ ์–ป์„ ์ˆ˜ ์žˆ์„๊นŒ์š”? type ExampleType = Promise type Result = MyAwaited // string ํ’€์ด type MyAwaited = T extends PromiseLike ? MyAwaited : T; Array vs ArrayLike, Promise vs PromiseLike ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์—๋Š” ArrayLike๋ผ๋Š”๊ฒŒ ์กด์žฌํ•œ๋‹ค. Array๋Š” ์ผ๋ฐ˜์ ์ธ ๋ฐฐ์—ด์„ ์˜๋ฏธํ•˜๋Š”๋ฐ, ArrayLike๋Š” ๋ฌด์—‡์ผ๊นŒ? ์ด๋ฅผ ์•Œ์•„๋ณด๊ธฐ ์œ„ํ•ด lib.es5.d.ts์— ๊ฐ€์„œ ๊ฐ๊ฐ์˜ ์ŠคํŽ™์„ ์‚ดํŽด๋ณด์ž. Array ArrayL..

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

Intro Filtering requirements have grown. We need to be able to filter any kind of Persons. ํ•„ํ„ฐ๋ง ์š”๊ตฌ์‚ฌํ•ญ์ด ๋Š˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ Person์˜ ๋ชจ๋“  ์ข…๋ฅ˜๋ฅผ ๊ตฌ๋ถ„ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. Exercise Fix typing for the filterPersons so that it can filter users and return User[] when personType='user' and return Admin[] when personType='admin'. Also filterPersons should accept partial User/Admin type according to the personType. `criteria` argument sh..

[TS] type-challenges: 43. Exclude

๋ฌธ์ œ T์—์„œ U์— ํ• ๋‹นํ•  ์ˆ˜ ์žˆ๋Š” ํƒ€์ž…์„ ์ œ์™ธํ•˜๋Š” ๋‚ด์žฅ ์ œ๋„ค๋ฆญ Exclude๋ฅผ ์ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๊ตฌํ˜„ํ•˜์„ธ์š”. type Result = MyExclude // 'b' | 'c' ํ’€์ด ํƒ€์ž…์ด ์•„๋‹Œ ๋‹จ์ˆœ ๋ฌธ์ œ์˜€๋‹ค๊ณ  ์ƒ๊ฐํ•ด๋ณด์ž function MyExclude(T, U) { if(T === U) return; else return T; } ์ด๋Ÿฐ ๋Š๋‚Œ์ด๋‹ค. T์— ํ•ด๋‹นํ•˜๋Š” ํƒ€์ž…๋“ค์ค‘ U์™€ ๊ฐ™์€ ํƒ€์ž…์ด ์žˆ๋‹ค๋ฉด ๊ทธ๊ฑด ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š๊ณ , ๊ฐ™์ง€ ์•Š๋‹ค๋ฉด ๋ฐ˜ํ™˜ํ•˜๋Š” ๋กœ์ง์ด๋‹ค. ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์—์„œ ===์— ํ•ด๋‹นํ•˜๋Š” ๋ถ€๋ถ„์€ extends๋กœ ๋Œ€์ฒด ๊ฐ€๋Šฅํ•˜๊ณ  ์•„๋ฌด๊ฒƒ๋„ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋Š” never ์ด๋ผ๋Š” ํƒ€์ž…์œผ๋กœ ์“ธ ์ˆ˜ ์žˆ๊ฒ ๋‹ค. type MyExclude = T extends U ? never : T; ์ถœ์ฒ˜ https://github.com..

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

Intro Time to filter the data! In order to be flexible we filter users using a number of criteria and return only those matching all of the criteria. We don't need Admins yet, we only filter Users. ๋ฐ์ดํ„ฐ๋ฅผ ์„ ๋ณ„ํ•  ์ฐจ๋ก€์ž…๋‹ˆ๋‹ค! ๋ณด๋‹ค ์œ ์—ฐํ•ด์ง€๊ธฐ ์œ„ํ•ด ์šฐ๋ฆฌ๋Š” ๊ธฐ์ค€์„ ํ‘œ์‹œํ•˜๋Š” ์ˆซ์ž๋ฅผ ์ด์šฉํ•˜์—ฌ ์œ ์ €๋“ค์„ ํ•„ํ„ฐ๋งํ•˜๊ณ , ์˜ค์ง ์ด ๋ชจ๋“  ๊ธฐ์ค€์— ๋งž๋Š” ์œ ์ €๋“ค๋งŒ ๋ฆฌํ„ดํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ์•„์ง Admin๋“ค์€ ํ•„์š”ํ•˜์ง€ ์•Š๊ณ  User๋“ค๋งŒ ํ•„ํ„ฐ๋งํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. Exercise Without duplicating type structures, modify filterUsers functio..

[TS] type-challenges: 18. Length of Tuple

๋ฌธ์ œ ๋ฐฐ์—ด(ํŠœํ”Œ)์„ ๋ฐ›์•„ ๊ธธ์ด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ์ œ๋„ค๋ฆญ Length๋ฅผ ๊ตฌํ˜„ํ•˜์„ธ์š”. type tesla = ['tesla', 'model 3', 'model X', 'model Y'] type spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT'] type teslaLength = Length // expected 4 type spaceXLength = Length // expected 5 ํ’€์ด type Length = T['length']; ๊ฐ„๋‹จํ•˜๊ฒŒ ์ด๋ ‡๊ฒŒ ํ‘œํ˜„ํ–ˆ๋”๋‹ˆ Type 'readonly ["tesla", "model 3", "model X", "model Y"]' does not satisfy the constrai..

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

Intro As we introduced "type" to both User and Admin it's now easier to distinguish between them. Once object type checking logic was extracted into separate functions isUser and isAdmin - logPerson function got new type errors. ์œ ์ €์™€ ์–ด๋“œ๋ฏผ์— ๋Œ€ํ•ด type์„ ์†Œ๊ฐœํ–ˆ๋“ฏ์ด, ์ด์ œ ์ด ๋‘˜์„ ๊ตฌ๋ถ„ํ•˜๋Š”๊ฑด ์‰ฌ์›Œ์กŒ์Šต๋‹ˆ๋‹ค. ๋กœ์ง์„ ๊ฒ€์‚ฌํ•˜๋Š” ๊ฐ์ฒด ํƒ€์ž…์„ ์ถ”์ถœํ•ด์„œ isUser๊ณผ isAdmin ํ•จ์ˆ˜์— ๋ถ„๋ฆฌํ•ด์„œ ๋„ฃ์—ˆ๋”๋‹ˆ logPerson ํ•จ์ˆ˜์— ์ƒˆ๋กœ์šด ํƒ€์ž…์—๋Ÿฌ๊ฐ€ ์ƒ๊ฒผ์Šต๋‹ˆ๋‹ค Exercise Figure out how to help TypeScrip..

[TS] type-challenges: 14. First of Array

๋ฌธ์ œ ๋ฐฐ์—ด(ํŠœํ”Œ) T๋ฅผ ๋ฐ›์•„ ์ฒซ ์›์†Œ์˜ ํƒ€์ž…์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ์ œ๋„ค๋ฆญ First๋ฅผ ๊ตฌํ˜„ํ•˜์„ธ์š”. type arr1 = ['a', 'b', 'c'] type arr2 = [3, 2, 1] type head1 = First // expected to be 'a' type head2 = First // expected to be 3 ํ’€์ด ๋น„๊ต์  ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ๋ผ์„œ T[0]์„ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ํ–ˆ๋Š”๋ฐ, ๊ทธ๋žฌ๋”๋‹ˆ []์ธ๊ฒฝ์šฐ never์— ๋Œ€ํ•œ ์ผ€์ด์Šค์— ๊ฑธ๋ ค์„œ ๋ถ„๊ธฐ์ฒ˜๋ฆฌ๋ฅผ ์ง„ํ–‰ํ•ด์คฌ๋‹ค type First = T extends [] ? never : T[0]; ์ถœ์ฒ˜ https://github.com/type-challenges/type-challenges/blob/main/questions/00014-easy-first/README.ko.m..

๋ฐ˜์‘ํ˜•