You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

44 lines
1011 B

// 1.参数个数:参数少的可以赋值给参数多的
type F1 = (a: number) => void
type F2 = (a: number, b: number) => void
let f1: F1
let f2: F2
// 参数少的 f1 可以赋值给参数多的 f2 。 例: f2 = f1
// 但是参数多的不能赋值给参数少的
// 2.参数类型:相同位置的参数类型要相同兼容
// 参数类型是原始类型
type F3 = (a: number) => void
type F4 = (a: number) => void
let f3: F3
let f4: F4
// 相同位置和相同类型的参数,可以参数少的可以赋值给参数多的,也可以参数多的赋值给参数少的。 例:f3 = f4 f4 = f3
// 参数类型是对象类型
interface Point2D {
x: number
y: number
}
interface Point3D {
x: number
y: number
z: number
}
type F5 = (p: Point2D) => void // 相当于有两个参数
type F6 = (p: Point3D) => void // 相当于有三个参数
let f5: F5
let f6: F6
// 参数少的可以赋值给参数多的,但是参数多的不可以赋值给参数少的