Issue
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?
Solution
The language specification says on p.64f
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[..]
example:
// 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})
});
};
Answered By - Andreas Frische
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.