type Length<T extends readonly any[]> = T['length']
Solution by thukyaw11 #35528
// ์ฌ๊ธฐ ํ์ด๋ฅผ ์
๋ ฅํ์ธ์
type Length<T> = T extends {length: number} ? T["length"] : never
Solution by Gwanghun-Im #35499
type Length<T extends ReadonlyArray<unknown>> = T['length']
Solution by gangnamssal #35469
type Length<T extends readonly PropertyKey[]> = T['length']
or
type Length<T extends readonly PropertyKey[]> = T extends {length: infer L} ? L : never
Solution by RanungPark #35432
// your answers
type Length<T extends readonly any[]> = T["length"];
Solution by Sathiyapramod #35418
// your answers
type Length<T extends readonly any[]> = T["length"];
Solution by Sathiyapramod #35412
type Length<T> = 'length' extends keyof T ? T['length'] : never
Solution by Pig-Cola #35366
type Length<T extends readonly unknown[]> = T['length']
Solution by gyeounjeong #35354
type Length<T extends readonly any[]> =
T extends [infer first, ...infer rest] ? Length<rest> : 1
I was so excited because this's my first time coming up with a solution before referring others :)
Solution by watanaki #35187
type Length<T extends readonly any[]> = T['length'];
Solution by raeyoung-kim #34937
type Length<T extends readonly any[]> = T['length']
Solution by Kim-Ji-Seop #34924
type Length<T extends readonly any[]> = T['length']
Solution by jsk3342 #34905
type Length<T extends readonly any[]> = T["length"]
Solution by 56aiden90 #34876
๋ฐฐ์ด(ํํ)์ ๋ฐ์ ๊ธธ์ด๋ฅผ ๋ฐํํ๋ ์ ๋ค๋ฆญ 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
์ฝ๊ธฐ์ ์ฉ unknown ํ์
์ ๋ฐฐ์ด๋ก ํ์
์ ์ ํํ๊ณ T["length"]
์ธ๋ฑ์ค ์ ๊ทผ์ ํตํด ํ์
์ ์ ์ฒด ๊ธธ์ด๋ฅผ ๋ฐํํ์ฌ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์๋ค.
type Length<T extends readonly unknown[]> = T["length"];
Solution by MyeonghoonNam #34831
type Length<T extends readonly any[]> = T['length']
Solution by eunsukimme #34810
type Length<T extends readonly any[]> = T['length']
Solution by kang-kibong #34744
Completely forgot that if we use const
, then type is inferred with maximum accuracy, which allows to know specific details such as exact length of touple :)) without const
, Length
will just return number
type
type Length<T extends readonly any[]> = T['length']
Solution by Git-I985 #34699
type Length<T> = T extends { length: infer L } ? L : T;
type Length<T> = T extends readonly any[] ? T["length"] : T;
Solution by lephuthuc2001 #34698
// ไฝ ็็ญๆก
type Length<T extends readonly any[]> = T['length']
Solution by yunxiaopw #34683
// your answers
type Length<T extends readonly any[]> = T["length"];
Solution by zeyuanHong0 #34675
type Length<T> = T extends readonly any[] ? T['length'] : never;
Solution by nathan2slime #34657
type Length<T extends readonly any[]> = T["length"]
Solution by devshinthant #34542
type Length<T extends readonly any[]> = T['length'];
Solution by ktim816 #34421
type Length<T extends readonly any[]> = T['length']
Solution by rookie-luochao #34358
type Length<T extends readonly string[] > = T["length"]
type Length<T extends readonly PropertyKey[] > = T["length"]
type Length<T extends readonly unknown[] > = T["length"]
type Length<T extends readonly unknown[] > = T extends { length: infer L } ? L : never
// infer L means that L is a alias of length
Solution by binhdv155127 #34325
type Length<T extends readonly any[]> = T['length'];
Solution by wxh-cyber #34293
type Length<T extends unknown[]> = T["length"]
Solution by souzaramon #34271
type Length<T extends readonly any[]> = T['length']
type Length2<T extends readonly any[], N = T['length']> =
T extends [infer F, ...infer R]
? Length<R>
: N;
Solution by bkdragon0228 #34252
type Length<T extends readonly any[]> = T["length"]
Solution by Fmanuel809 #34190