StudyForYou / ouahhan-typescript-with-react

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

๐Ÿ”ฅtype-challenges_03_ 3312 - Parameters #39

Closed hyeyoonS closed 3 months ago

hyeyoonS commented 3 months ago

Parameters ์‰ฌ์›€ #infer #tuple #built-in

by midorizemi @midorizemi

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

๋‚ด์žฅ ์ œ๋„ค๋ฆญ Parameters<T>๋ฅผ ์ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๊ตฌํ˜„ํ•˜์„ธ์š”.

์˜ˆ์‹œ:

const foo = (arg1: string, arg2: number): void => {}

type FunctionParamsType = MyParameters<typeof foo> // [arg1: string, arg2: number]

๋Œ์•„๊ฐ€๊ธฐ ์ •๋‹ต ๊ณต์œ ํ•˜๊ธฐ ์ •๋‹ต ๋ณด๊ธฐ
drizzle96 commented 3 months ago

์ด๋ฏธ ๋‹ค ๊ฐ™์ด ํ’€๊ธด ํ–ˆ์ง€๋งŒ ๊ธฐ๋ก์ฐจ,,ใ…Žใ…Ž

type MyParameters<T extends (...args: any[]) => any> = T extends (...args: infer U) => any ? U : never