javascript - 如何将 Typescript 函数签名分配给命名函数?
问题描述
使用 typescript 时,我倾向于以这种模式编写函数:
const myFunc: MyFuncType = (input, otherInput, moreInput) => {
return input + otherInput + moreInput;
};
但是,我似乎无法弄清楚如何将接口传递给命名函数。
我想做这样的事情:
function myFunc<MyFuncType>(input, otherInput, moreInput) {
return input + otherInput + moreInput;
}
在第二个示例中,Typescript 分配any
给我的所有函数参数,而不是推断每个参数的类型。模式是const
分配函数签名的唯一方法吗?
谢谢。
解决方案
推荐阅读
- typescript - 如何使`[key: string]: string`出现在NestJS Swagger生成中
- google-cloud-platform - 使用自定义服务帐户在 GCP 中创建 VM 时,KMS 权限出现 400 错误
- sql - Postgres - 从组中检索最新记录的最有效方法
- ruby-on-rails - Rails迁移,如何更改表列
- javascript - ReactJS 中的警告。组件正在更改要控制的非受控输入。这可能是由于值从 undefined 变为
- mysql - 如何在连接表中创建不可重复的连接
- python - 使用 python 输出作为另一个守护进程的输入
- amazon-web-services - 对象和类型的组合 any - Terraform
- laravel - laravel - 邮递员返回 HTML 而不是 JSON?
- vue.js - VueJS Vee-Validate 验证未发生