admin管理员组文章数量:1026154
I have a typescript file containing a class definition:
if (window.console == null) {
(<any>window).console = {
error: function (a) {
},
log: function (a) {
}
};
}
class SendMessage {
//.....
}
After the pilation to javascript (by VS2015), I get the error on the line with the class definition:
Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
I have found that I have to use the strict mode. But why and how can I use it in typescript?
Thanks
I have a typescript file containing a class definition:
if (window.console == null) {
(<any>window).console = {
error: function (a) {
},
log: function (a) {
}
};
}
class SendMessage {
//.....
}
After the pilation to javascript (by VS2015), I get the error on the line with the class definition:
Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
I have found that I have to use the strict mode. But why and how can I use it in typescript?
Thanks
Share Improve this question asked Nov 10, 2015 at 15:51 o..oo..o 1,9317 gold badges36 silver badges65 bronze badges1 Answer
Reset to default 11It's because it's piling to ES6 and the browser is requiring that block-scoped declarations be used in strict mode.
You can fix this by using strict mode. To do that add...
"use strict";
...to the top of every file.
However, I think you probably want to change the pilation target from ES6 to ES5. If you are using tsconfig.json
, change "target": "es6"
to "target": "es5"
. Doing that will...pile to ES5...and so block-scoped declarations will be changed appropriately so "use strict";
will not be required. Additionally, more browsers will support your code. Right now runtime ES6 support is still not widespread.
Note that if you are not using tsconfig.json, you might have to change the target in the project properties' typescript build tab as shown here:
I have a typescript file containing a class definition:
if (window.console == null) {
(<any>window).console = {
error: function (a) {
},
log: function (a) {
}
};
}
class SendMessage {
//.....
}
After the pilation to javascript (by VS2015), I get the error on the line with the class definition:
Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
I have found that I have to use the strict mode. But why and how can I use it in typescript?
Thanks
I have a typescript file containing a class definition:
if (window.console == null) {
(<any>window).console = {
error: function (a) {
},
log: function (a) {
}
};
}
class SendMessage {
//.....
}
After the pilation to javascript (by VS2015), I get the error on the line with the class definition:
Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
I have found that I have to use the strict mode. But why and how can I use it in typescript?
Thanks
Share Improve this question asked Nov 10, 2015 at 15:51 o..oo..o 1,9317 gold badges36 silver badges65 bronze badges1 Answer
Reset to default 11It's because it's piling to ES6 and the browser is requiring that block-scoped declarations be used in strict mode.
You can fix this by using strict mode. To do that add...
"use strict";
...to the top of every file.
However, I think you probably want to change the pilation target from ES6 to ES5. If you are using tsconfig.json
, change "target": "es6"
to "target": "es5"
. Doing that will...pile to ES5...and so block-scoped declarations will be changed appropriately so "use strict";
will not be required. Additionally, more browsers will support your code. Right now runtime ES6 support is still not widespread.
Note that if you are not using tsconfig.json, you might have to change the target in the project properties' typescript build tab as shown here:
本文标签:
版权声明:本文标题:javascript - Typescript and Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outs 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1743624309a2002747.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论