Search code examples
arraystypescriptobjectany

What does any[]=[] datatype mean in TypeScript?


I'm working on a project in a company and there's a variable declared like this

  chainTypeList: any[]=[];

and I'm not able to access it's values like this.

this.chainTypeList.chainTypeCode;

It shows this error : Property 'chainTypeCode' does not exist on type 'any[]'.


Solution

  • This is looks like typescript's typing.

    This means that this is an array of any value. An it's initilized as an empty one.

    The any value literally means that you can push any value and value type into this array.

    You can't access it by using this:

    this.chainTypeList.chainTypeCode;
    

    because it's an array and not an object. That's why you get the error:

    Property 'chainTypeCode' does not exist on type 'any[]'.

    It should only be something like this:

    this.chainTypeList
    

    or

    this.chainTypeList[0]
    

    If you want a specific position of the array. Just change the number for the position you want to obtain.