StudyForYou / ouahhan-typescript-with-react

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

๐Ÿ”ฅtype-challenges_07_ 00018 - Length of Tuple #51

Open drizzle96 opened 1 month ago

drizzle96 commented 1 month ago

Length of Tuple ์‰ฌ์›€ #tuple

by sinoon @sinoon

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

๋ฐฐ์—ด(ํŠœํ”Œ)์„ ๋ฐ›์•„ ๊ธธ์ด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ์ œ๋„ค๋ฆญ Length<T>๋ฅผ ๊ตฌํ˜„ํ•˜์„ธ์š”.

์˜ˆ์‹œ:

type tesla = ['tesla', 'model 3', 'model X', 'model Y']
type spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT']

type teslaLength = Length<tesla>  // expected 4
type spaceXLength = Length<spaceX> // expected 5

๋Œ์•„๊ฐ€๊ธฐ ์ •๋‹ต ๊ณต์œ ํ•˜๊ธฐ ์ •๋‹ต ๋ณด๊ธฐ
hyeyoonS commented 1 month ago
type Length<T extends readonly unknown[]> = T["length"];
drizzle96 commented 1 month ago

์—๋Ÿฌ๋Œ€๋กœ ๊ณ ์น˜๊ธด ํ–ˆ์œผ๋‚˜ ์™œ readonly๊ฐ€ ์žˆ์–ด์•ผ ๋˜๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ์Œ

type Length<T extends readonly unknown[]> = T['length']
qooktree1 commented 1 month ago
type Length<T extends string[]> = T['length'];

์ˆ˜์ •๋ณธ

type Length<T extends readonly unknown[]> = T['length'];
drizzle96 commented 1 month ago
type Length<T extends { length: number }> = T['length']