当前位置: 首页> 娱乐> 明星 > 最新中国b2b网站排名_企业网站维护工作计划_搜索引擎营销_西安seo优化

最新中国b2b网站排名_企业网站维护工作计划_搜索引擎营销_西安seo优化

时间:2025/7/9 7:52:31来源:https://blog.csdn.net/qq_38935512/article/details/142529494 浏览次数:0次
最新中国b2b网站排名_企业网站维护工作计划_搜索引擎营销_西安seo优化

typeScript 学习

1.基础类型

  • 基础
let decLiteral: number = 6;
let decLiteral: string = '22';
let decLiteral: any = '22';
let decLiteral: number[] = [1, 2, 3];  / Array<number>
let decLiteral: [string, number] = ['xsa',2];  //元组  
  • 枚举
enum Color {Red = 1, Green, Blue}
let colorName: string = Color[2];alert(colorName);  // 显示'Green'因为上面代码里它的值是2  red如果=0 那就是blue
  • 函数返回
声明一个void类型的变量没有什么大用,因为你只能为它赋予undefined和null
function warnUser(): void {alert("This is my warning message");
}
function warnUser(): boolean {return false
}function buildName(firstName: string = "Smith") {return firstName + " " + lastName;
}function buildName(firstName: string, ...restOfName: string[]) {return firstName + " " + restOfName.join(" ");
}
  • Never
// 返回never的函数必须存在无法达到的终点
function infiniteLoop(): never {while (true) {}
}
  • 类型断言as 我比TypeScript 更知道这个值的类型,听我的
let someValue: any = "this is a string";let strLength: number = (someValue as string).length;

2.变量声名

type C = { a: string, b?: number }
function f({ a, b }: C): void {// ...
}

3.接口 interface

interface LabelledValue {label: string;width?:number //可选readonly xxxx:number  //只读 只有在创建的时候才可以修改[propName: string]: any;  //key 为stringprivate state: any;  //私有
}function printLabel(labelledObj: LabelledValue) {console.log(labelledObj.label);
}let myObj = {size: 10, label: "Size 10 Object"};
printLabel(myObj);
  • 继承接口
nterface Shape {color: string;
}interface Square extends Shape {sideLength: number;
}let square = <Square>{};
square.color = "blue";
square.sideLength = 10;

4.泛型

 <T> 有点像any 可以传入任意类型function loggingIdentity<T>(arg: T): T {console.log(arg.length);  // Error: T doesn't have .lengthreturn arg;
}function loggingIdentity<T>(arg: T[]): T[] {console.log(arg.length);  // Array has a .length, so no more errorreturn arg;
}
关键字:最新中国b2b网站排名_企业网站维护工作计划_搜索引擎营销_西安seo优化

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: