I am working on a vanilla JavaScript project in VS Code and have set up jsconfig.json
. Here is an example of the code I am using:
/**
* @param {(arg: string) => void} nestedFunction
*/
function myFunction(nestedFunction) {
// Some logic here
}
myFunction("text"); // Error is highlighted
myFunction(() => {}); // Error not highlighted due to fewer arguments
myFunction((a, b) => {}); // Error not highlighted due to more arguments and "a" as type "any"
The same issue occurs when using TypeScript with the function defined as:
function myFunction(nestedFunction: (arg: string) => void) {
// Some logic here
}
VS Code correctly identifies errors when passing the wrong argument type to myFunction
(such as a string), but does not flag any issues when passing a function that doesn't match the format of nestedFunction
. Why is this?
In case it's relevant, here is the content of my jsconfig.json
file:
{
"compilerOptions": {
"checkJs": true,
"target": "ES6"
}
}