【发布时间】:2020-07-08 09:28:57
【问题描述】:
谁能给我解释一下为什么我下面写的代码似乎不能区分以下两种类型:
[1] () => void(不带参数的函数类型不返回任何内容)
[2] () => () => void(一个不带参数的函数并返回一个不带参数且不返回任何内容的函数)。
例如:
const function2 = (): () => void => {
return (): void => {};
};
export const function1 = (arg: () => void): void => {
console.log(arg);
};
function1(function2); // Should NOT pass type checker as the return type is not void
function1(function2()); // Should pass type checker
或者,有人可以告诉我如何让function1(function2) 引发 Typescript 编译错误。
【问题讨论】:
标签: typescript typescript-typings