let age: number=18//变量定义
const fun=(msg:string):string=>{}//方法定义
interface Cat {//接口定义
name: string,
age?: number//? age属性是可选的
}
const c1: Cat = {name: 'jack', age: 1}
class User {//定义类,类可以实现接口和继承类
name: string
constructor(name: string) {//构造方法
this.name = name
}
study() {
console.log(this.name + '正在学习')
}
}
const user = new User('jack')
console.log(user)
user.study()
string | |
number | |
boolean | |
number[],string[],boolean[] | 数组 |
any | 任意类型 |
type,interface | 复杂类型 |
()=>void | 函数类型,声明函数的参数和返回值 |
"a"|"b" | 字面量类型,限制变量和方法参数的类型 |
class Animal | class类 |