当前位置:网站首页>TypeScript学习
TypeScript学习
2022-08-03 23:57:00 【涵。】
1 any和unknow
unknow只能作为父属性,unknow不能访问对象的属性和方法
2 在对象中引入任意属性
interface p={
age:1
[propName:string]:any
}
3 IArguments类数组
function add(...args:any):void{
let arr:IArguments=arguments
}
4 通过接口定义数组
interface A{
[index:number]:number
}
5 函数重载
function fn(name:string,age:number):void
function fn(name:number):void
function fn(name:any,age?:number):void{
}
6 当返回值类型为boolean,而值类型为number时,使用!!将类型进行强制转换
7 联合类型
interface People={
}
interface Man={
}
const peter=(man:Prople&Man):void=>{
}
8 类型断言
(type as string)或<string>type
9 protected和private的区别
protected内部和子类可以访问,private子类不可以访问
10 设置为static的变量使用类名访问,不需要实例化
class Person{
static age:number=1
}
console(Person.age)
设置为static的方法只能访问设置为static的变量
class Person{
public name:string='xie'
static age:number=1
static show(){
console(this.age)
}
}
11 继承抽象类,抽象方法需要重写
边栏推荐
- Scala basics [regular expressions, framework development principles]
- 孙宇晨:Web3.0和元宇宙将协助人类更加全面地进入网络世界
- The Beijing E-sports Metaverse Forum was successfully held
- Creo 9.0二维草图的诊断:着色封闭环
- 代码重构:面向单元测试
- RSS feeds WeChat public - feed43 asain
- 使用unbound在RHEL7上搭建DNS服务
- libnet
- 苹果对高通说:我4.45亿美元买下一个新园区,可能计划加快基带芯片自研
- Justin Sun: Web3.0 and the Metaverse will assist mankind to enter the online world more comprehensively
猜你喜欢
随机推荐
"Miscellaneous" barcode by Excel as a string
七夕活动浪漫上线,别让网络拖慢和小姐姐的开黑时间
C语言实验十五 文件
jav一键生成数据库文档
Salesforce的中国区业务可能出现新变化,传言可能正在关闭
通过whl安装第三方包
POE交换机全方位解读(下)
win10+cuda11.7+pytorch1.12.0安装
Salesforce's China business may see new changes, rumors may be closing
FastDFS 一文读懂
超级完美版布局有快捷键,有背景置换
- the skip/skipif Pytest learning
MCS-51单片机,定时1分钟,汇编程序
Apple told Qualcomm: I bought a new campus for $445 million and may plan to speed up self-development of baseband chips
小身材有大作用——光模块寿命分析(二)
【杂项】如何将指定字体装入电脑然后能在Office软件里使用该字体?
Prometheus监控Harbor(二进制版)
搭建好pytorch环境后,pip和conda指令不能用
Talking about the future development direction of my country's industrial parks
易动纷享--测试实习生视频面试









