定义对象类型
定义对象类型
类型别名 type
type关键字可以定义一个复杂类型的数据,如数组、对象等
代码示例
type point = {
x: number,
y: string
}
使用type声明包含其他type关键字包含的数据
为避免类型重复定义
代码示例
type point5 = {
x: number,
y: string
}
type point6 = point5 & {
z: boolean
}
const zb_type: point6 = {
x: 1,
y: '2',
z: false
}
接口申明类型 interface
代码示例
interface point3 {
x: Number,
y: String
}