Ethan
Ethan

Reputation: 27

Javascript parameters do not show methods / hints in VSCode

When using a variable after i click, it will give me the methods that are available that I can use. but using parameters it doesn't show anything. is there a way I can fix this in vscode?

Here is an exmaple


function stringIncludes(str) {
    str.//doesnt show anything
    let string = "string"
    string.//shows all the methods for strings
}

I was thinking of specifying the parameters data structure but I don't think you can do that in javascript if you can please let me know how!

Upvotes: 1

Views: 537

Answers (1)

Axekan
Axekan

Reputation: 699

The reason this happens in because VSCode has no idea what type the variable str is.

For VSCode you can use JSDoc to help IntelliSense understand what you are doing in Vanilla JavaScript (when not using TypeScript)

For your example, it could look like this:

/**
 * Determine if string includes...
 * @param {string} str - string to check
 */
function stringIncludes(str) {
    str.//doesnt show anything
    let string = "string"
    string.//shows all the methods for strings
}

Upvotes: 3

Related Questions