当前位置:网站首页>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 继承抽象类,抽象方法需要重写
边栏推荐
猜你喜欢
随机推荐
孙宇晨受邀参加36氪元宇宙峰会并发表主题演讲
查看CUDA、pytorch等的版本号
响应式织梦模板餐饮酒店类网站
Node.js的基本使用(三)数据库与身份认证
POE交换机全方位解读(下)
The longest substring that cannot have repeating characters in a leetcode/substring
【LeetCode】最长回文子序列(动态规划)
一文搞定 SQL Server 执行计划
【深度学习】基于tensorflow的服装图像分类训练(数据集:Fashion-MNIST)
分布式事务框架 seata
【并发编程】ReentrantLock的lockInterruptibly()方法源码分析
【LeetCode】最长公共子序列(动态规划)
Creo 9.0二维草图的诊断:加亮开放端点
OpenCV 图像拼接
A Preliminary Study of RSS Subscription to WeChat Official Account-feed43
The curl using guide
图论-虚拟节点分层建图
"Miscellaneous" barcode by Excel as a string
密码学基础以及完整加密通讯过程解析
JVM垃圾回收总结(未完待续)