[Angular] The $any() type cast function

Sometimes a binding expression triggers a type error during AOT compilation and it is not possible or difficult to fully specify the type. To silence the error, you can use the $any() cast function to cast the expression to the anytype as in the following example:

<p>The item's undeclared best by date is: {{$any(item).bestByDate}}</p>

Using $any() prevents TypeScript from reporting that bestByDate is not a member of the item object.

The $any() cast function also works with this to allow access to undeclared members of the component.

<p>The item's undeclared best by date is: {{$any(this).bestByDate}}</p>

The $any() cast function works anywhere in a binding expression where a method call is valid.

上一篇:Vue+TS 开发 海康威视 Web3.0控件


下一篇:08、TypeScript 装饰器