03057-easy-push

Back

// that's cool, thanks all Ts developer
type Push<T extends any[] , U> = [...T, U]

Solution by leongaooo #36928

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

Solution by AlexBraunMagic #36912

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

Solution by shaishabcoding #36848

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

Solution by Abdullah-Elsayed01 #36791

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

/* _____________ Test Cases _____________ */
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]>>,
]

type errors = [
  // @ts-expect-error
  Expect<Equal<Push<number[], string>, string[]>>,
  // @ts-expect-error
  Expect<Equal<Push<string[], number>, [string, number]>>,
]

Solution by AnastasiaSv #36768

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

Solution by tungulin #36719

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

Solution by seungdeok #36682

// your answers

type Push<T, U> = T extends [...infer TType] ? [...TType,U] : never

Modifications and Suggestions are welcomed ๐ŸŽ‰

Solution by SubramaniyanTN #36675

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

This implementation is better for the following reasons: Greater Compatibility: Supports both readonly and regular array types, making it suitable for more scenarios.

Avoids type errors caused by readonly input types.

Aligns with TypeScript Best Practices: Using readonly any[] is more general, reducing potential type conflicts.

It will be better than type Push<T extends any[], U> = [...T, U]

Solution by spike014 #36625

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

Solution by tungulin #36608

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

Solution by ChemieAi #36556

type push<T extends Array<unknow>, U> = [...T, U]

Solution by Divcutu #36455

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

Solution by alirezaprime #36417

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

Solution by justBadProgrammer #36392

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

Solution by HelloWook #36384

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

Solution by tac-tac-go #36361

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

Solution by 1Alex4949031 #36316

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

Solution by asylbekduldiev #36291

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

Solution by AleksandrShcherbackov #36147

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

Solution by reonce #36050

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

Solution by karazyabko #36032

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

Solution by codingaring #35942

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

Solution by Sensuele #35802

// ไฝ ็š„็ญ”ๆกˆ
type Push<T extends readonly unknown[], U extends unknown> = [...T, U]

Solution by naruto-823 #35795

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

Solution by ydkim120 #35732

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

Solution by gangnamssal #35493

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

Solution by RanungPark #35443

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

const inputArr: Push<[1, 2], "3"> = [1, 2, "3"];

Solution by Sathiyapramod #35420

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

const inputArr: Push<[1, 2], "3"> = [1, 2, "3"];

Solution by Sathiyapramod #35414

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

Solution by gyeounjeong #35361