admin管理员组文章数量:1186702
I'm studying Javascript using Visual Code and every time a similar exercise that uses 'event' (the event shows in the code with the strikethrough like e̶v̶e̶n̶t̶) appears I can't complete it because of this annoying issue. In the description pop up a warning showing the issue ("event is deprecated ts(6385)"). I look out in the forums and stack over flow but I can not find any answer for this problem, only a few places says the lib dom and @deprecated, but I don't what to do.
Please, any way to help and learn to pass this problem out will be very useful.
function sayMyFirstName(element){
alert("My First name is..." + element.value)
}
function sayMyLastName(){
console.log(event)
}
I'm studying Javascript using Visual Code and every time a similar exercise that uses 'event' (the event shows in the code with the strikethrough like e̶v̶e̶n̶t̶) appears I can't complete it because of this annoying issue. In the description pop up a warning showing the issue ("event is deprecated ts(6385)"). I look out in the forums and stack over flow but I can not find any answer for this problem, only a few places says the lib dom and @deprecated, but I don't what to do.
Please, any way to help and learn to pass this problem out will be very useful.
function sayMyFirstName(element){
alert("My First name is..." + element.value)
}
function sayMyLastName(){
console.log(event)
}
Share
Improve this question
edited Oct 29, 2020 at 17:06
Brian Tompsett - 汤莱恩
5,88372 gold badges61 silver badges133 bronze badges
asked Oct 29, 2020 at 4:33
AllesonCoelhoAllesonCoelho
1311 gold badge1 silver badge4 bronze badges
4
|
4 Answers
Reset to default 13It sounds like you're getting TypeScript validation for a simple JS project. There are several things you can try:
In your settings file (settings.json):
"typescript.validate.enable": false
... OR ...
In your .js source file(s):
/*tslint:disabled*/
A separate issue is why you're getting the "deprecation" warning in the first place. This is the reason:
https://developer.mozilla.org/en-US/docs/Web/API/Window/event
The read-only Window property event returns the Event which is currently being handled by the site's code. Outside the context of an event handler, the value is always undefined.
You should avoid using this property in new code, and should instead use the Event passed into the event handler function. This property is not universally supported and even when supported introduces potential fragility to your code.
In other words, "event" should really be passed as an argument to a JS event handler. You shouldn't be using the global object; you shouldn't NEED to use the global object.
Here are a few good tutorials:
- Introduction to events (MDN.com)
- JavaScript Events
Strong suggestion:
If you're learning JavaScript, please make sure your study materials are up-to-date (definitely covering ES6!). This is a good book: Secrets of the JavaScript Ninja 2nd Edition
You can use "window.event" to replace the deprecated "event".
It looks to me that the TypeScript Validator is saying the implicit passing of event is deprecated. A simple fix would be to pass the event into the function as a parameter
function sayMyLastName(event){
console.log(event)
}
I'm migrating a lot of functionality from JS to Angular and found this issue a lot
You just need to open >Preferences: Open Workspace Settings (JSON)
by Ctrl + Shift + P
in VSCode then add this line to JSON file "editor.showDeprecated": false
to disable a show deprecated in case if you only need to some workspace.
If you want to disable all workspace then use >Preferences: Open Settings (JSON)
instead.
本文标签:
版权声明:本文标题:javascript - I'm trying to call event but my Visual Code say ("event is deprecated ts(6385)") - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738360105a2080571.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
event is deprecated ts(6385)
at the line you showed, "console.log(event)"? Is there other, relevant code you're NOT showing us? Where is "event" declared? Is the file suffix "js"? Or ".ts"? In any case - read my suggestions below. – paulsm4 Commented Oct 29, 2020 at 4:52