我正在观看 typescript 教程,有一次我必须编写这行代码
var squareItSimpler = function(h:number, w:number) => h * w;
但我就是无法让它工作。我不断收到错误
The command "C:\Program Files (x86)\Microsoft SDKs\TypeScript\tsc.exe" --module AMD --target ES3....exited with code 1
我只是不知道该怎么办,我在这里做错了什么吗?
有趣的是下面的作品:
var squareItSimplest = (h:number, w:number) => h * w;
我正在使用 TypeScript 0.9.0.1
最佳答案
当您在 Typescript 中执行类似 lambda 表达式时,您会省略 function
关键字。也许您的教程有错误。
编辑 — 来自 the spec :
TypeScript supports arrow function expressions, a new feature planned for ECMAScript 6. Arrow function expressions are a compact form of function expressions that omit the function keyword and have lexical scoping of this.
关于javascript - typescript lambda 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17479172/