带有泛型的 Typescript 箭头函数的语法是什么? [英] What is the syntax for Typescript arrow functions with generics?
本文介绍了带有泛型的 Typescript 箭头函数的语法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
打字稿手册目前没有关于箭头函数的内容.正常功能可以使用以下语法进行一般输入:例子:
The typescript handbook currently has nothing on arrow functions. Normal functions can be generically typed with this syntax: example:
function identity<T>(arg: T): T {
return arg;
}
箭头函数的语法是什么?
What is the syntax for arrow functions?
推荐答案
语言规范在 p.64f 上说
The language specification says on p.64f
形式的构造T > ( ... ) => { ... } 可以解析为带有类型参数或类型断言的箭头函数表达式应用于没有类型参数的箭头函数.它被解析为前者[..]
A construct of the form < T > ( ... ) => { ... } could be parsed as an arrow function expression with a type parameter or a type assertion applied to an arrow function with no type parameter. It is resolved as the former[..]
示例:
// helper function needed because Backbone-couchdb's sync does not return a jqxhr
let fetched = <
R extends Backbone.Collection<any> >(c:R) => {
return new Promise(function (fulfill, reject) {
c.fetch({reset: true, success: fulfill, error: reject})
});
};
这篇关于带有泛型的 Typescript 箭头函数的语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文