type Unshift<T, U> = T extends any[] ? [U, ...T]: [];
Solution by dailyco #35207
type Unshift<T extends any[], U> = [U, ...T];
Solution by IsaacYouKorea #35206
type Unshift<T extends unknown[], P> = [P, ...T]
Solution by ClarityOfMind #35003
type Unshift<T extends any[], U> = [U, ...T];
Solution by raeyoung-kim #34946
type Unshift<T extends unknown[], U> = T extends never[] ? [U] : [U, ...T]
Solution by 56aiden90 #34887
type Unshift<T extends unknown[], U> = [U, ...T]
Solution by eunsukimme #34817
type Unshift<T extends unknown[], U> = [U, ...T]
Solution by Yuriy113 #34736
// your answers
type Unshift<T extends unknown[], U> = [U, ...T]
Solution by zeyuanHong0 #34726
type Unshift<T extends any[], U> = T["length"] extends 0 ? [U] : [U, ...T];
Solution by lephuthuc2001 #34708
type Unshift<T extends readonly any[], U> = [U, ...T]
Solution by Git-I985 #34706
type Unshift<T, U> = T extends any[] ? [U, ...T] : T
Solution by nathan2slime #34664
type Unshift<T extends unknown[], U> = [U, ...T]
// your answers
Solution by Rustamaha #34555
type Unshift<T extends unknown[], U> = [U,...T]
Solution by devshinthant #34550
type Unshift<T extends unknown[], U> = [U, ...T]
Solution by binhdv155127 #34474
// ์ฌ๊ธฐ ํ์ด๋ฅผ ์
๋ ฅํ์ธ์
type Unshift<T extends readonly unknown[], U> = [U, ...T];
Solution by LeeKangHyun #34465
We should add U at array T's first place. So, declare a new array(type) and add U. And, spread T's elements.
// your answers
type Unshift<T extends any[], U> = [U, ...T]
Solution by dev-jaemin #34459
type Unshift<T extends readonly any[], U> = [U, ...T];
Solution by ktim816 #34429
type Unshift<T extends any[], U> = [U, ...T]
Solution by bkdragon0228 #34426
// your answers
type Unshift<T extends any[], U> = [U, ...T]
Solution by gobielJonathan #34400
type Unshift<T extends any[], U> = [U, ...T];
Solution by wxh-cyber #34370
type Unshift<T extends unknown[], U> = [U, ...T]
Solution by souzaramon #34318
Array.unshift
์ ํ์
๋ฒ์ ์ ๊ตฌํํ์ธ์.
type Result = Unshift<[1, 2], 0>; // [0, 1, 2]
ํฌ๊ฒ ์ด๋ ค์ด ๋ฌธ์ ๋ ์๋์์ต๋๋ค. ์ ๋ ฅ๋ฐ์ U๋ฅผ ๋ฐฐ์ด์ ๊ฐ์ฅ ์์์์ ๋ฐฐ์นํ์ฌ ์๋ก์ด array ํ์ ์ ์์ฑํฉ๋๋ค.
์ฌ์ค ์ฌ๋ด์ด์ง๋ง ๋ค์๊ณผ ๊ฐ์ด ๋ฐฐ์ด๋ก ์ ์ธํ ํ์
์ ํ์ฉ๋๊ฐ ๋์ง ์์ต๋๋ค.
์ ๋์ธ ํ์
์ ๋ฐฐ์ด๋ณด๋ค ๊ฐ๋จํ๊ณ ๋ช
ํํฉ๋๋ค. ํ์
์ ์ฝ์ ๋, ๋ฐฐ์ด๋ณด๋ค ์ ๋์ธ ํ์
์ด ๋ ์ง๊ด์ ์ด๊ณ ์ดํดํ๊ธฐ ์ฝ์ต๋๋ค.
์ ๋์ธ ํ์
์ TypeScript์ ํ์
์์คํ
๊ณผ ์์ฐ์ค๋ฝ๊ฒ ํตํฉ๋ฉ๋๋ค.
์๋ฅผ ๋ค์ด, ์ ๋์ธ ํ์
์ ํจ์์ ๋งค๊ฐ๋ณ์๋ ๋ฐํ ๊ฐ์ ํ์
์ผ๋ก ์ฝ๊ฒ ์ฌ์ฉํ ์ ์์ต๋๋ค.
/* _____________ ์ฌ๊ธฐ์ ์ฝ๋ ์
๋ ฅ _____________ */
type Unshift<T extends any[], U> = [U, ...T];
/* _____________ ํ
์คํธ ์ผ์ด์ค _____________ */
import type { Equal, Expect } from "@type-challenges/utils";
type cases = [
Expect<Equal<Unshift<[], 1>, [1]>>,
Expect<Equal<Unshift<[1, 2], 0>, [0, 1, 2]>>,
Expect<Equal<Unshift<["1", 2, "3"], boolean>, [boolean, "1", 2, "3"]>>
];
Solution by adultlee #34115
type Unshift<T extends unknown[], U> = [U, ...T];
Solution by ProvorovOleksii #34084
type Unshift<T extends unknown[], U> = [U, ...T]
Solution by ouzexi #33974
type Unshift<T extends unknown[], U> = [U,...T]
Solution by hyojinLee-git #33947
type Unshift<T extends unknown[], U> = [U, ...T]
Solution by notsecret32 #33865
type Unshift<T extends any[], U> = [U, ...T]
Solution by okasyun #33835
type Unshift<T extends any[], U> = [U, ...T]
pushใฎๅ็ญใใปใผ้ใซใใใฎใฟใ
้
ๅใ็ปๅ ดใใๅ ดๅใฏใ ใใใexntends type[]
ใๅฎฃ่จใใๆนใ่ฏใใใใ
any
ใฏใงใใใฐไฝฟใใใใชใใๅ้กใซใใฃใฆใฏไฝฟใฃใฆใใๅใ้ใใใฆใใใฎใงใใใฃใจไธๅฏงใซๅฎฃ่จใใฆใ่ฏใใใ
Solution by okabe-yuya #33827
type Unshift<T extends readonly unknown[], U> = [U, ...T]
Solution by veralex #33758