property 'length' does not exist on type 'T' 1

property ‘length’ does not exist on type ‘T’

const result = (arr:T[]):T => {
  return arr[arr.length - 1] 
}

result([1,2,3])

Here is what the above code is Doing:
1. We’re defining a generic type T
2. We’re defining a function that takes an array of T’s and returns a T
3. We’re returning the last element of the array

Similar Posts