What is the difference between any and any[ ]?

后端 未结 4 2207
旧时难觅i
旧时难觅i 2021-02-19 13:34

What is the difference between any and any[ ]?


Example 1 (working as expected)

name1: any;
name2: any[];
this.name1 = this.name2;
4条回答
  •  花落未央
    2021-02-19 14:13

    If you use any, both on the left and on the right side of an assignment, you are basically say to Typescript not use type checking.

    In any is on left side it means the the variable you want to assign the value can accept any type, and therefore it accepts anything including an object of type any[].

    If the type any is on the right side and you have myVar: any[] on the left side, you are basically say to Typescript not use type checking. Considering that type checking is not applied at run time, you would end up with myVar being filled with whatever you may have on the right side of the assignment.

提交回复
热议问题