5

I've been searching for an answer to this with no luck. VSCode offers some suggestions like in this example:

enter image description here

However, many suggestions do not show up. For example, when passing an event there is no suggestion for e.preventDefault, or any of the associated methods or data that will accompany an event.

In the tutorial I'm watching I don't know if they are using 'javascript completions' with Sublime or if they have an extension in VSCode, but if it's possible to do this with Visual Studio I would really like to continue using it.

Example from the tutorial below: enter image description here

1 Answer 1

2

VS Code can infer the types in many cases but sometimes you need to explicitly annotate them using jsdocs (more info).

In the addItem case, add a @param jsdoc annotation stating that e is an Event:

/**
 * @param {Event} e
 */
function addItem(e) { ... }

This is not required if you use an inline function for addEventListener because we can infer the type in that case:

obj.addEventListerner('submit', function(e) { ... })
Sign up to request clarification or add additional context in comments.

2 Comments

Annotate all the methods? That's not even a serious suggestion. It's not because it cannot infer the type it's because the buggy half-baked plug-in does not work.
@RickO'Shea Your comment doesn't contribute anything. If you're going to complain, at least propose an alternative

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.