问题描述
我具有函数类型的这种类型别名。
type ADD_FUNCTION = (x: number,y: number) => number;
我可以这样做:
type ADD_FUNCTION = (x: number,y: number) => number;
const add: ADD_FUNCTION = (x,y) => {
return x + y;
};
const result = add(1,2);
console.log(result);
之所以起作用,是因为我将函数存储在名为add
的变量ADD_FUNCTION
中。
但是,如果我不想将该函数存储在变量中并用常规的命名函数声明它,该怎么办?
function add(x,y) {
return x + y;
}
是否有一种语法可以让我使用type
别名ADD_FUNCTION
定义该函数类型?
以下代码不起作用:
function add: ADD_FUNCTION (x,y) {
return x + y;
}
注意::我知道可以使用以下代码,但是我真的很想使用type alias
。
function add(x: number,y: number): number {
return x + y;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)