我正在观看打字稿教程,有一点我必须编写这行代码
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
I'm watching a typescript tutorial and at one point i have to write this line of code
var squareItSimpler = function(h:number, w:number) => h * w;But i just can't get it to work. I keep getting the error
The command "C:\Program Files (x86)\Microsoft SDKs\TypeScript\tsc.exe" --module AMD --target ES3....exited with code 1And i just don't know what to do, am i doing something wrong here ?
The funny this is that the fallowing works:
var squareItSimplest = (h:number, w:number) => h * w;I'm using TypeScript 0.9.0.1
最满意答案
当您在Typescript中执行类似lambdas的操作时,请不要使用function关键字。 也许你的教程有错误。
编辑 - 从规范 :
TypeScript支持箭头函数表达式,这是ECMAScript 6计划的新功能.Arow函数表达式是函数表达式的一种紧凑形式,它省略了function关键字并对此进行了词法作用域。
When you do lambdas like that in Typescript, you leave off the function keyword. Perhaps your tutorial has an error.
edit — from 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.
更多推荐
发布评论