Unshift
Implement the generic version of Array.unshift
For example:
tstypeCannot find name 'Unshift'.2304Cannot find name 'Unshift'.Result =<[1, 2], '3'> // [1, 2, '3'] Unshift
tstypeCannot find name 'Unshift'.2304Cannot find name 'Unshift'.Result =<[1, 2], '3'> // [1, 2, '3'] Unshift
Solution ✅
tstypeUnshift <Arr ,Value > =Arr extends readonly any[] ? [Value , ...Arr ] : nevertypeResult =Unshift <[1, 2], 0> // [0, 1, 2,]typeResult2 =Unshift <[], 1> // [1]typeResult3 =Unshift <[1, 2], '3'> // ['3', 1, 2]typeResult4 =Unshift <['1', 2, '3'], boolean> // [boolean, '1', 2, '3']
tstypeUnshift <Arr ,Value > =Arr extends readonly any[] ? [Value , ...Arr ] : nevertypeResult =Unshift <[1, 2], 0> // [0, 1, 2,]typeResult2 =Unshift <[], 1> // [1]typeResult3 =Unshift <[1, 2], '3'> // ['3', 1, 2]typeResult4 =Unshift <['1', 2, '3'], boolean> // [boolean, '1', 2, '3']