使用 Typescript,如何键入功能性 True 函数?

Using Typescript, how do I type the functional True function?

作为背景,我正在研究 "Flock of Functions" 并尽力将这些 Javascript 示例转换为类型化的 Typescript。请参阅 https://github.com/glebec/lambda-talk/blob/master/src/index.js#L152 以供参考。 True 函数 return 第一个柯里化参数,忽略第二个参数。

考虑以下 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'));

假设我想保留 "explicit-function-return-type" 规则,如何去掉 ESLint 禁用注释?换句话说,我想正确输入 True 函数。

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

]

我该怎么做才能设置 return 类型或以其他方式正确输入此内容,这样我就不需要禁用 ESLint 规则?

(_els): boolean => thn;

它对你的情况有用吗?

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

const T: True = <T_>(thn) => <T_>(_els):T_ => thn;