这种方式不能限制后面的函数体吗,我前面规定了参数和无返回值void,后面函数体不写参数,返回值也有,但是不报错
下面是测试代码,只有最后一段代码在编译的时候会报错
const add: (num1: number, num2: number) => void = (num1: number, num2: number) => {
return 'string'
}
const add2: (num1: number, num2: number) => number = (num1: number, num2: number) => {
return num1 + num2
}
const fun: (num: number) => void = function (num: number) {
return 'string'
}
let a = fun(1)
console.log(a)
const fun2: (num: number) => void = function () {
return 'string'
}
type Fun = (num: number) => void
const fun1: Fun = function (num: number) {
return 'string'
}
function Fun1(num: number): void{
}
不太明白
|