typescript
1.let/const
typescript
let msg:string='hello'
let age:number=11
let isDone:boolean=true
2.数据类型
typescript
string
number
boolean
any
void
null
undefined
never
object
array
tuple
enum
3.interface
typescript
interface Person{
name:string;
age:number;
sex?:string;
readonly school:string;
greet():void;
[prop:string]:string;
}
let person:Person={name:'ivan',age:30}
4.联合类型与交叉类型
typescript
let v:string|number=12
type Admin=Employee&Manager
5.泛型
typescript
function ide<T>(arg:T):T{
return arg
}
let out=ide<number>(12)
6.类型别名
typescript
type UserId=string
let id:UserId='test11'
7.类型断言
typescript
let v:any='test'
let d:number=(<string>v).length
let c:number=(v as string).length
8.装饰器
typescript
function log(value:any,constructor:any){
console.log(`${constructor.name}`)
}
@log
class Student{
constructor(){
console.log('constructor')
}
}
const s=new Student()