StudyForYou / ouahhan-typescript-with-react

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

๐Ÿ”ฅtype-challenges_08_ 00898 - Includes #52

Open drizzle96 opened 1 month ago

drizzle96 commented 1 month ago

Includes ์‰ฌ์›€ #array

by null @kynefuk

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

JavaScript์˜ Array.includes ํ•จ์ˆ˜๋ฅผ ํƒ€์ž… ์‹œ์Šคํ…œ์—์„œ ๊ตฌํ˜„ํ•˜์„ธ์š”. ํƒ€์ž…์€ ๋‘ ์ธ์ˆ˜๋ฅผ ๋ฐ›๊ณ , true ๋˜๋Š” false๋ฅผ ๋ฐ˜ํ™˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ:

type isPillarMen = Includes<['Kars', 'Esidisi', 'Wamuu', 'Santana'], 'Dio'> // expected to be `false`

๋Œ์•„๊ฐ€๊ธฐ ์ •๋‹ต ๊ณต์œ ํ•˜๊ธฐ ์ •๋‹ต ๋ณด๊ธฐ
drizzle96 commented 1 month ago
type Includes<T extends readonly any[], U> = {
  [P in T[number]]: true
}[U] extends true ? true : false;
hyeyoonS commented 1 month ago
type Includes<T extends readonly any[], U> =
  T['length'] extends 0 ? false 
    : Equal<U, T[0]> extends true ? true 
      : T extends [any, ...infer R] ? Includes<R, U> : false;