03057-easy-push

Back

type Push<T extends unknown[], P> = [...T, P]

Solution by ClarityOfMind #35002

type Push<T extends any[], U> = [...T, U];

Solution by raeyoung-kim #34945

type Push<T extends any[], U> = T extends never[] ? [U] : [...T, U] // your answers

Solution by 56aiden90 #34882

type Push<T extends any[], U> = [...T, U]

Solution by eunsukimme #34816

type Push<T, U> = T extends Array<unknown> ? [...T, U] :never

Solution by Yuriy113 #34735

// your answers
type Push<T extends any[], U> = [...T, U];

Solution by zeyuanHong0 #34721

type Push<T extends any[], U> = [...T,U]

Solution by lephuthuc2001 #34709

type Push<T extends readonly any[], U> = [...T, U]
image

Solution by Git-I985 #34705

type Push<T, U> = T extends any[] ? [...T, U] : [U]

Solution by nathan2slime #34663

type Push<T extends readonly unknown[], U> = [...T,U]

Solution by devshinthant #34549

type Push<T extends unknown[], U> = [...T, U]

Solution by binhdv155127 #34473

// ์—ฌ๊ธฐ ํ’€์ด๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”
type Push<T extends readonly unknown[], U> = [...T, U];

Solution by LeeKangHyun #34464

type Push<T extends readonly any[], U> = [...T, U];

Solution by ktim816 #34428

// your answers
type Push<T extends any[],U> = [...T, U]

Solution by gobielJonathan #34399

type Push<T extends any[], U> = [...T, U]

Solution by bkdragon0228 #34385

type Push<T extends any[], U> = [...T, U]

Solution by rookie-luochao #34364

Just use a spread operator.

// your answers
type Push<T extends any[], U> = [...T, U]

Solution by dev-jaemin #34330

type Push<T extends any[], U> = [...T, U];

Solution by wxh-cyber #34323

type Push<Xs extends unknown[], X extends unknown> = [...Xs, X]; 

Solution by souzaramon #34270

// ไฝ ็š„็ญ”ๆกˆ

type Push<T extends unknown[], U> = [...T,U]

Solution by W-fitTiger #34249

type Push<T extends any[], U> = [...T, U]

Solution by quitone #34197

๋ฌธ์ œ ์„ค๋ช…

Array.push์˜ ์ œ๋„ค๋ฆญ ๋ฒ„์ „์„ ๊ตฌํ˜„ํ•˜์„ธ์š”.

์˜ˆ์‹œ:

type Result = Push<[1, 2], "3">; // [1, 2, '3']

ํ’€์ด

์ด ๋˜ํ•œ ์–ด๋ ค์šด ๋ฌธ์ œ๋Š” ์•„๋‹ˆ์—ˆ์Šต๋‹ˆ๋‹ค. ๋ฌธ์ œ์ค‘ ํ•˜๋‚˜์ธ, unshift ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ๋‹ค๋ฉด, ๋™์‹œ์— ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์˜€์Šต๋‹ˆ๋‹ค.

Solution

/* _____________ ์—ฌ๊ธฐ์— ์ฝ”๋“œ ์ž…๋ ฅ _____________ */

type Push<T extends any[], U> = [...T, U];

/* _____________ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค _____________ */
import type { Equal, Expect } from "@type-challenges/utils";

type cases = [
	Expect<Equal<Push<[], 1>, [1]>>,
	Expect<Equal<Push<[1, 2], "3">, [1, 2, "3"]>>,
	Expect<Equal<Push<["1", 2, "3"], boolean>, ["1", 2, "3", boolean]>>
];

Solution by adultlee #34116

type Push<T extends any[], U extends any> = [...T, U];

Solution by ProvorovOleksii #34083

type Push<T extends unknown[], U> = [...T, U];

Solution by ouzexi #33972

type Push<T extends unknown[], U> = [...T,U]

Solution by hyojinLee-git #33946

type Push<T extends unknown[], U> = [...T, U]

Solution by notsecret32 #33864

type Push<T extends any[], U> = [...T, U]

Solution by okasyun #33834

type Push<T extends any[], U> = [...T, U]

concatใฎๅ•้กŒใฎๅฟœ็”จใง่งฃใ‘ใŸใ€‚ Tๅž‹ใซๅฏพใ—ใฆextends any[]ใ‚’ๅฎฃ่จ€ใ—ใชใ„ใจ...TใŒใ‚จใƒฉใƒผใซใชใ‚‹ใ€‚

Solution by okabe-yuya #33826

type Push<T extends unknown[], U> = [...T, U]

Solution by veralex #33757

type Push<T extends Array<unknown>, K> = [...T, K]

Solution by Danny101201 #33739