TypeScript 任意值
作者:互联网
任意值
任意值(Any)用来表示允许赋值为任意类型
1. any类型,允许被赋值为任意类型
let myFavoriteNumber: any = 'seven';
myFavoriteNumber = 7;
2. 任意值的属性和方法
声明一个变量为任意值之后,对它的任何操作,返回的内容的类型都是任意值
在任意值上访问任何属性都是允许的
let anyThing: any = 'hello';
console.log(anyThing.myName);
console.log(anyThing.myName.firstName);
也允许调用任何方法
let anyThing: any = 'Tom';
anyThing.setName('Jerry');
anyThing.setName('Jerry').sayHello();
anyThing.myName.setFirstName('Cat');
3.未声明类型的变量
变量如果在声明的时候,未指定其类型,那么它会被识别为任意值类型
let something;
something = 'seven';
something = 7;
something.setName('Tom');
标签:TypeScript,anyThing,let,something,类型,任意,any 来源: https://blog.csdn.net/yizhenxinghe/article/details/120710419