Push
Implement the generic version of Array.push
For example:
tstypeCannot find name 'Push'.2304Cannot find name 'Push'.Result =<[1, 2], '3'> // [1, 2, '3'] Push
tstypeCannot find name 'Push'.2304Cannot find name 'Push'.Result =<[1, 2], '3'> // [1, 2, '3'] Push
Solution ✅
tstypePush <Arr ,Value > =Arr extends readonly any[] ? [...Arr ,Value ] : never;typeResult =Push <[1, 2], '3'> // [1, 2, '3']typeResult2 =Push <[], 1> // [1]typeResult3 =Push <[1, 2], '3'> // [1, 2, '3']typeResult4 =Push <['1', 2, '3'], boolean> // ['1', 2, '3', boolean]
tstypePush <Arr ,Value > =Arr extends readonly any[] ? [...Arr ,Value ] : never;typeResult =Push <[1, 2], '3'> // [1, 2, '3']typeResult2 =Push <[], 1> // [1]typeResult3 =Push <[1, 2], '3'> // [1, 2, '3']typeResult4 =Push <['1', 2, '3'], boolean> // ['1', 2, '3', boolean]