type First<T extends any[]> = T extends [infer A,...infer U] ? A:never
Solution by TaueFenCheng #35533
type First<T extends any[]> = T extends [infer F, ...any[]] ? F : never;
Solution by thukyaw11 #35527
// ์ฌ๊ธฐ ํ์ด๋ฅผ ์
๋ ฅํ์ธ์
type First<T extends any[]> = T extends [] ? never : T[0]
Solution by Gwanghun-Im #35498
type First<T extends any[]> = T['length'] extends 0 ? never : T[0];
Solution by gangnamssal #35468
type TupleToObject<T extends readonly PropertyKey[]> = {
[P in T[number]] : P
}
Solution by RanungPark #35431
type First<T extends any[]> = T extends [] ? never : T[0]
Solution by RanungPark #35430
// your answers
type First<T extends any[]> = T[0];
Solution by Sathiyapramod #35419
// your answers
type arr1 = ["1", "2", "3"];
type First<T extends any[]> = T[0];
type head1 = First<arr1>;
Solution by Sathiyapramod #35411
type FirstElement<T extends any[]> = T extends [] ? never : T[0]
// ไฝ ็็ญๆก
Solution by dixiaioping #35386
type First<T extends any[]> = T extends [] ? never : T[0]
Solution by gyeounjeong #35352
// ไฝ ็็ญๆก
type First<T extends any[]> = T[0] extends undefined ? undefined : T[0];
// JS ็ๆ่ทฏ๏ผ [][0] === undefined
type First<T extends any[]> = T extends [infer F, ...any[]] ? F : undefined;
// TS ็ๆ่ทฏ๏ผ็ฑปๅๆจๅฏผ็ฌฌไธไธชๅผ็็ฑปๅ
// ๅจ่ฟไธคไธช็ญๆกไธญ๏ผๆ้ฝ่ฟๅไบ undefined ่ไธๆฏ never๏ผ่ฎฉๅฎๆดๅ JS ็็ๅฎ่ฟ่กๆ
ๅต
Solution by ren-142326 #35254
type First<T extends unknown[]> = T extends [] ? never : T[0]
Solution by Muntazir-sd #35221
type First<T extends any[]> = T extends [infer F, ...any[]] ? F : never;
Solution by raeyoung-kim #34927
type First<T extends any[]> = T extends [] ? never : T[0]
Solution by Kim-Ji-Seop #34923
type First<T extends any[]> = T extends [] ? never : T[0]
Solution by jsk3342 #34903
type First<T extends any[]> = T extends never[] ? never : T[0]
Solution by 56aiden90 #34875
๋ฐฐ์ด(ํํ) T
๋ฅผ ๋ฐ์ ์ฒซ ์์์ ํ์
์ ๋ฐํํ๋ ์ ๋ค๋ฆญ First<T>
๋ฅผ ๊ตฌํํ์ธ์.
์กฐ๊ฑด๋ถ extends์ ์์ ์ฌ์ฉํ๋ ํค์๋์ด๋ค.
ํ์ ์คํฌ๋ฆฝํธ๊ฐ ์์ง์ด ๋ฐํ์ ์ํฉ์์ ํ์ ์ ์ถ๋ก ํ ์ ์๋๋ก ํ๊ณ , ์ถ๋ก ํ ํ์ ๊ฐ์ infer ํ์ ํ๋ผ๋ฏธํฐ U ์ ํ ๋นํด์ค๋ค.
type Foo<T> = T extends { a: infer U; b: infer U } ? U : never;
type T10 = Foo<{ a: string; b: string }>; // string
type T11 = Foo<{ a: string; b: number }>; // string | number
์กฐ๊ฑด๋ถ extends์ ๊ณผ ์ผํญ์ฐ์ฐ์๋ฅผ ํ์ฉํ์๊ณ , ๋ฐฐ์ด์ ์คํ๋ ๋ ์ฐ์ฐ๊ณผ infer ํค์๋๋ฅผ ํตํด ์กฐ๊ฑด๋ถ ํ์ ์ถ๋ก ์ผ๋ก ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์๋ค.
// ์ฌ๊ธฐ ํ์ด๋ฅผ ์
๋ ฅํ์ธ์
type First<T extends unknown[]> = T extends [infer A, ...infer rest]
? A
: never;
Solution by MyeonghoonNam #34822
// your answers
type First<T extends any[]> = T extends [] ? never : T[0] extends any ? T[0] : never
Solution by eunsukimme #34809
type First<T extends any[]> = T extends [] ? never : T[0]
Solution by kang-kibong #34743
type First<T extends any[]> = T extends []? never: T[0];
Solution by lephuthuc2001 #34697
// your answers
type First<T extends any[]> = T extends [infer First, ...infer Rest] ? First : never;
Solution by zeyuanHong0 #34672
type First<T extends any[]> = T extends [infer F, ...any[]] ? F : never
Solution by nathan2slime #34655
type First<T extends any[]> = T extends [] ? never : T[0]
Solution by devshinthant #34541
type First<T extends readonly any[]> = T extends [infer First, ...infer Reset] ? T[0] : never
Solution by JayoonKoo #34519
type First<T extends any[]> = T extends [] ? never : T[0]
Solution by Hailey0930 #34489
type First<T extends any[]> = T extends [] ? never : T[0];
Solution by ktim816 #34420
// your answers
type First<T extends any[]> = T extends [] ? never: T[0]
Solution by gobielJonathan #34394
type First<T extends any[]> = T extends [] ? never : T[0];
type First<T extends any[]> = T['length'] extends 0 ? never : T[0];
Solution by znar #34384
type First<T extends any[]> = T extends [] ? never : T[0]
Solution by rookie-luochao #34357
ๆฌ้ข่งฃ็ญ๏ผ
export type First<T extends any[]> = T extends [infer first, ...any[]]? first: never;
ไปฅไธๆฏๅฏนไธๅ็ๆฐ็ปๆไฝ็TSๅฎ็ฐ๏ผ
//ๆฐ็ปๆๅไธไธชๅ
็ด
export type Last<T extends any[]>=T extends [...any,infer L]?L:never;
//ๅผนๅบๆฐ็ปๆๅไธไธชๅ
็ด ๏ผPop๏ผ
export type Pop<T extends any[]>=T extends [...infer P,infer R]?P:never;
//ๅๆฐ็ปๆซๅฐพๆทปๅ ไธไธชๅ
็ด ๏ผPush๏ผ
export type Push<T extends any[],U>=T extends [..T,U];
//ๅผนๅบๆฐ็ปๅผๅคด็ๅ
็ด ๏ผShift๏ผ
export type Shift<T extends any[]>=T extends [infer F,...infer R]?R:never;
//ๅฐๆฐ็ปๆๅไธไธชๅ
็ด ็ฝฎไบๆฐ็ปๅผๅคด๏ผUnshift๏ผ
export type Unshift<T extends any[],U>=[U,...T];
//่ฟๆฅไธคไธชๆฐ็ป๏ผConcat๏ผ
export type Concat<T extends any[],V extends any[]>=[...T,...V];
//ๆฐ็ปๅ่ฝฌ๏ผReverse๏ผ
export type Reverse<T extends any[]>=T extends [infer Head,...infer Rest]?[...Reverse<Rest>,Head]:T;
//่ฟๆปคๆๅฎๅฏน่ฑก๏ผFilterOut๏ผ
export type FilterOut<T extends any[],F>=T extends [infer First,...infer Rest]?(First extends F?FilterOut<Rest,F>:[First,...FilterOut<Rest,F>]):T;
่ฏดๆ๏ผๆฐ็ปๅ่ฝฌๅ่ฟๆปคๆๅฎๅฏน่ฑก็ๅฎ็ฐ้ฝ้็จไบ้ๅฝ็ๆนๅผ๏ผไปฅ่พพๅฐๅฏนๆฐ็ปไธญๆฏไธชๅ ็ด ่ฟ่กๆๅฎ็ๆไฝใ
Solution by wxh-cyber #34322