How to remove TypeScript warning: property 'length' does not exist on type '{}'

I read a similar post here: How can I stop "property does not exist on type JQuery" syntax errors when using Typescript?

Which explains that I can cast to <any>.

This worked for me:

function testArray(){
    console.log((<any>myArr[1]).length);
}

Option 1: upgrade to bleeding-edge compiler and get union types

Option 2: Add a type annotation to the variable declaration:

var myArr: any[] = ['one', [[19, 1], [13, 1], [86, 1], [12, 2]],
             'two',    [[83, 1], [72, 1], [16, 2]],
             'three',  [[4, 1]]];

function testArray(){
    console.log(myArr[1].length);
}

i faced this error before,you have to cast the type to any and when you use generics you have to extends.

check the example blow:

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

result([1,2,3])