1

How do I properly JSDoc the function below?

function foo() {
  foo.counter = 1 + (foo.counter || 0)
}

Currently TS type checking (in vscode, with checkJs=true) complains: Property 'counter' does not exist on type '() => void'

1

1 Answer 1

0

You can document static members with JSDoc. I would use a namepath for this and so an extra block:

function foo() {
}

/**
 * My static counter
 * @name foo.counter
 * @type {number}
 */
foo.counter = 0;

Now my IDE (VS Code) is able to see it as a property and pull out the documentation:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

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.