一、 typescript中的类型
二、对各类型进行举例子
function sum (a:number,b:number): number{
return a+b;
}
console.log(sum(2,123))
s
let q:"string"
let a:"male"|"female";
a="male";
a="female"
type myType=1|2|3|4|5;
let d:myType;
let f:myType;
d=1;
d=2;
let b:any;
b=1;
b="hello";
b=true;
let c:unknown;
c=q;
function fn():void{
}
let e:{name:string,age?:number};
b={name:"孙悟空"}
let r:{name:string,[proName:string]:any};
r={name:"yuam",age:12,gender:12}
let t:(a:number,b:number)=>number;
let u :string[]
u=["a","b"]
let i:number[]
i=[1,2,3]
let o:[string ,string]
o=['1','2']
enum Gender{
male=0,
female=1,
}
let p:{nameTwo:string,gender:Gender};
p={
nameTwo:'小王',
gender:Gender.female
}
console.log(p.gender===Gender.female);
|