StudyForYou / ouahhan-typescript-with-react

์šฐ์•„ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ with ๋ฆฌ์•กํŠธ ์Šคํ„ฐ๋”” ๋ ˆํฌ ๐Ÿงต
4 stars 0 forks source link

๐Ÿ”ฅtype-challenges_09_ 00189 - Awaited #53

Open drizzle96 opened 1 month ago

drizzle96 commented 1 month ago

Awaited ์‰ฌ์›€ #promise #built-in

by Maciej Sikora @maciejsikora

๋„์ „ํ•˜๊ธฐ    English ็ฎ€ไฝ“ไธญๆ–‡ ๆ—ฅๆœฌ่ชž

Promise์™€ ๊ฐ™์€ ํƒ€์ž…์— ๊ฐ์‹ธ์ธ ํƒ€์ž…์ด ์žˆ์„ ๋•Œ, ์•ˆ์— ๊ฐ์‹ธ์ธ ํƒ€์ž…์ด ๋ฌด์—‡์ธ์ง€ ์–ด๋–ป๊ฒŒ ์•Œ ์ˆ˜ ์žˆ์„๊นŒ์š”?

์˜ˆ์‹œ: ๋“ค์–ด Promise<ExampleType>์ด ์žˆ์„ ๋•Œ, ExampleType์„ ์–ด๋–ป๊ฒŒ ์–ป์„ ์ˆ˜ ์žˆ์„๊นŒ์š”?

type ExampleType = Promise<string>

type Result = MyAwaited<ExampleType> // string

์ถœ์ฒ˜: original article by @maciejsikora


๋Œ์•„๊ฐ€๊ธฐ ์ •๋‹ต ๊ณต์œ ํ•˜๊ธฐ ์ •๋‹ต ๋ณด๊ธฐ
drizzle96 commented 1 month ago
type MyAwaited<T> = T extends { then: (onfulfilled: (arg: infer U) => any) => any } ? MyAwaited<U> : T
drizzle96 commented 1 month ago
type MyAwaited<T> = T extends PromiseLike<infer U> ? MyAwaited<U> : T