1

作为背景,我正在浏览“Flock of Functions”并尽我所能将这些 Javascript 示例转换为类型化的 Typescript。请参阅https://github.com/glebec/lambda-talk/blob/master/src/index.js#L152以供参考。True 函数返回第一个 curried 参数,并忽略第二个。

考虑以下 Typescript 代码:

interface ElsFn<T> {
  (els: unknown): T;
}

interface True extends Function {
  <T>(thn: T): ElsFn<T>;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const T: True = (thn) => (_els) => thn;

console.log(T('true')('false'));

假设我想保留“显式函数返回类型”规则,我如何摆脱 ESLint 禁用注释?换句话说,我想正确键入 True 函数。

我的编辑告诉我问题(_els) => thn出在代码部分。它需要以某种方式输入。

在此处输入图像描述 ]

我可以做些什么来设置返回类型或以其他方式正确输入这个东西,这样我就不需要禁用 ESLint 规则?

4

2 回答 2

1

您仍然需要指定泛型参数和返回类型:

const T: True = <T_>(thn) => <T_>(_els):T_ => thn;
于 2020-04-02T09:07:02.273 回答
0
(_els): boolean => thn;

它对你的情况有用吗?

于 2020-04-02T07:33:23.283 回答