当前位置:网站首页>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 继承抽象类,抽象方法需要重写
边栏推荐
猜你喜欢
随机推荐
Use tf.image.resize() and tf.image.resize_with_pad() to resize images
The problem of disorganized data output by mnn model
curl使用指南
2022/8/3 Exam Summary
The world's first mass production, with the most fixed points!How does this AVP Tier1 lead?
FastDFS 一文读懂
Redis persistence method
[Paper Reading] TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
数据分析知识点搜集(纯粹的搜集)
代码重构:面向单元测试
rosbridge-WSL2 && carla-win11
北京电竞元宇宙论坛活动顺利召开
Creo9.0 绘制中心线
用两个栈模拟队列
【LeetCode】最长公共子序列(动态规划)
POE交换机全方位解读(上)
伦敦银最新均线分析系统怎么操作?
2021年数据泄露成本报告解读
The "interaction design" battle of the smart cockpit
Creo 9.0二维草图的诊断:重叠几何