Questions tagged [jsdoc]
JSDoc is a markup language for adding inline API documentation to JavaScript source code. This is distinct from the various tools that parse and manipulate code that follows the JSDoc syntax.
1,528
questions
0
votes
0
answers
17
views
JSDoc - Is there any way to give same type for multiple variables at once?
Is there any way to give same type for multiple variable at once in javascript?
Usally give type like this
/** @type {number} */
var a = 1;
/** @type {number} */
var b = 2;
it is hard to define every ...
0
votes
0
answers
38
views
Specify type as instance of a class?
I have a very specific case where I import an object containing class declarations, and I use it to create an instance as a property of another class. With class properties, I need to define a type, ...
0
votes
0
answers
19
views
Properly create dictionary of objects/classes while maintaining their documentation
If I have a class listView that has documentation and I put it in a dictionary:
/** Handles list models */
class listView{}
const views = { list: listView }
Then the property/key list doesn't have ...
-1
votes
0
answers
11
views
JSDOC Copy object property documentation to the key
I have an object that consolidates other objects and gives them simplified keys. The nested objects each have documentation that shows up when hovered. Is there a way for me to give the keys the same ...
0
votes
1
answer
22
views
Import JSDOC documentation from another file
How can I import the documentation for class foo in File B?
// FileA.js
/** This is a class */
class foo { }
export default objectThatContainsFoo // foo isn't directly exported
// FileB.js
/** @...
0
votes
0
answers
29
views
Why is the JSDoc comment not shown when filtering mapped keys?
I'm trying to create a config type for a class. I want the type to have all the properties as optional but without the functions of the of the class. Similar to "Partial" but without ...
0
votes
1
answer
10
views
JSDoc: Accept instances of base class and it's child classes in `@type` tag
I have a base class (Validator) that is extended by a child class (ValidatorRequired).
Then in another class I want to have a collection of instances that may be of base class type (Validator) or any ...
0
votes
1
answer
8
views
Any standard way to export structured js/json from jsdoc comments
I want to use jsdoc comments from a javascript file inside an interactive component (like property definitions appearing on hover), but I can’t find a way to do that as jsdoc is primarily intended to ...
3
votes
1
answer
30
views
How can you include inherited properties in type definitions generated from .js files by tsc?
I am trying to add typescript support to a vanilla javascript library via .d.ts files. I am trying to generate these type definition files with the "tsc" command, but I am running into many &...
0
votes
0
answers
11
views
Can you make JSDoc work in HTML when embeding JavaScript code?
Some backstory:
I am working on a .html file where I solve some JavaScript exercises. I write the exercise description as html where I also have a table with example inputs and their corresponding ...
0
votes
0
answers
15
views
How to specify the jsdoc rule for ESLint to recognize unused parameters?
In my projects I have an ESLint rule for unused parameters that can be silenced by adding a leading underscore to the parameter name:
/**
* Set the outer alternative number for this context ...
0
votes
2
answers
55
views
JSDoc return instance of generic type
In short, I'm looking to pass a generic type into a factory's constructor and have the factory return instances of the generic type.
As a small bonus, the generic I'm passing in is a class extension ...
0
votes
0
answers
17
views
How to get constant information on hover in Typescript file?
I use styled-components with typescript in VSCode. I have constants for font that I reuse and I want to see what this constant is about(info on font size, line height etc) when I hover over it.
My ...
0
votes
0
answers
14
views
How to inherit from a class but also infer custom properties
When I have an object of known type and want to add some properties to it. And I'm also too lazy to write an additional interface.
How can I get both inherited and infered types for properties on the ...
1
vote
2
answers
64
views
How to mark a property deprecated in a @typedef?
I would like to mark a property (for example, qux below) as deprecated:
/**
@typedef {object} Foo
@property {string} bar
@property {symbol} qux - How to deprecate it?
@deprecated @property {symbol}...
0
votes
0
answers
16
views
JSDoc - Types for multiple declarations, one after the other
I am currently using this:
/** @type {TagsLevel} */
export let list;
/** @type {string} */
export let tagListName;
/** @type {string | null} */
let srcTag = null;
/** @...
3
votes
1
answer
43
views
JSDoc override return type of inherited class method
I'm trying to provide a dynamic return type for an inherited method by passing the child Class to the parent. Please find a small example below. Currently it's not working and I'm thinking I am not ...
0
votes
1
answer
21
views
JSDoc not picking up on data child attribute type override
I've noticed a problem when working with a parent class that's extended by a child class.
Both classes have a 'data' attribute, in the parent class it's a generic 'Object' type and in the child class ...
1
vote
0
answers
37
views
JSDoc: how to define a type that's equal to object's property names- like Typescript's keyof?
I'm looking for a way to get an object's property names as a type using JSDoc.
Let there be a typedef of an object named Record
/**
* @typedef {{
date: string,
a1: string,
a2: ...
0
votes
1
answer
14
views
jsDoc : How do I make the @return type of my method the type of a local variable from it?
I'm making a javascript project and I want to make it as clean as possible, and for that I'm using jsDoc at the top of my methods.
For one of them, I would like to know if it's possible to specify as ...
0
votes
1
answer
42
views
Inquiry to write function to javascript Object JSDoc property
I need to put a function in a javascript object, how do I add a JSDoc comment in this case?
/**
* @typedef {Object} testObj
* @property {!String} testName - testName
* @property {?Function} [...
0
votes
0
answers
30
views
automatically specify variables types by their inits in functions
So currently I have this snippet of code outside of any function:
...
/** @type Phaser.Physics.Arcade.Group */
var stars;
var score = 0;
/** @type Phaser.GameObjects.Text */
var scoreText;
/** @type ...
0
votes
1
answer
27
views
Missing type definition information in VS Code when own Node.js package is published on NPM
I cannot figure out why, once my own efficy-enterprise-api NPM package is published, the type definitions (used by VS Code intellisense) are not available anymore compared to locally referencing the ...
0
votes
0
answers
9
views
JSDoc: Is it possible to describe an object type with a subset of another type definition's properties?
Given a type definition:
/**
* @typedef {object} Foo
* @property {string} someString
* @property {number} someNumber
*/
is there a way to create another type definition that includes only a ...
0
votes
0
answers
32
views
How to add variables and methods in callback parameters
I'm making a custom middleware package as a project, and I ran into a problem. In one of the files, I have some jsdoc types (trying to make the package small so no typescript) for the callback:
class ...
0
votes
0
answers
36
views
Forced symbol for the file with JSDoc `@name` returns an error that it does not exist
It is the code from the documentation (https://jsdoc.app/tags-name.html):
// @ts-check
/**
* @name highlightSearchTerm
* @function
* @global
* @param {string} term - The search term to highlight.
...
0
votes
0
answers
31
views
Construct signatures with JSDoc and TS-Pragma ts(2351)
I've a function that returns a constructor dynamically.
When I try to instantiate the new object it warns me
This expression is not constructable.
Type 'myConstructor' has no construct signatures.ts(...
0
votes
0
answers
28
views
JSDoc nested types not showing on VSCode
I have this code:
typedefs.js
/**
* A UUID.
* Example: 123e4567-e89b-12d3-a456-426655540000
*
* @typedef {string} uuid
*/
/**
* @typedef {Object} Notification
*
* @property {uuid} id - The ...
0
votes
1
answer
48
views
Using an imported type in JSDoc @typedef
I'm trying to reduce duplication in specifying my imported types as follows but I'm getting an error
/**
@typedef {import("../types/util")} util
@typedef {util.mapBehaviors} mapBehaviors
... ...
0
votes
0
answers
8
views
Difference Between @property and @type
Question is as the title.
When should I use @property/@prop and @type when documenting an object and its nested properties?
Code Sample
// JSDoc Schema
/**
* @typedef {Object} Profile - user profile
...
0
votes
0
answers
27
views
Reuse JSDoc comment between TypeScript interfaces
Let's say I have the following interfaces:
interface Foo {
/**
* A date string in the format `yyyy-MM-dd`
*/
archiveDate: string;
}
interface Bar {
/**
* A date string in the format `...
0
votes
0
answers
17
views
Merge two typedef files jsdoc
I have two separate typedef files.
typedefFirst.js
/**
* ControllerResponse
* @typedef {Object} ControllerResponse
* @property {Number} statusCode
* @property {{ data: (Object | Array )}} body
*/
...
0
votes
1
answer
15
views
Define type for higher order function
I have below controller which is a higher order method,
const CourseController = {
createCourse:
({ CourseService }) =>
async (httpRequest) => {
const course = await ...
0
votes
0
answers
32
views
jsdoc error ENOENT: no such file or directory, open './readme/readme.md'
I have already installed jsdoc with npm i -D jsdoc command and created jsdoc.json file. In package.json file there is script called doc and after doing npm run doc jsdoc throws an error Error: ENOENT: ...
1
vote
1
answer
65
views
VSCode intellisense doesn't detect Object type from JSDoc
I'm using JSDoc in my project having both javascript and typescript, and I notice that in my js file if a parameter is defined as Object type then VSCode intellisense shows it as type any.
/**
* @...
0
votes
0
answers
32
views
Unexpected line break in JSDoc
I'm getting a line break in a jsDoc popup and I'm not sure how to get rid of it.
Here's what the popup looks like with the @param tag, as expected:
But if I add a new line below it, the tag is split ...
-1
votes
1
answer
32
views
Visual Studio Code JSDoc hide @ tags in tooltip
I cannot figure out how to hide the '@' tags in the description. Let me show what I am talking about:
What is happening:
What I would like to hide (marked in red):
I thought @param should only ...
0
votes
1
answer
65
views
How to define Type of dynamically added global variables for Intellisense
I am defining four global variables from a forEach loop using a line similar to this:
global[name] = buffer
with buffer being the type from node.js
and currently have the very ugly way to get my ...
0
votes
0
answers
17
views
Babel removes jsdoc header comments. How to force it to keep them?
I have a .ts file with following code:
/**
* @ab 3.0
* @xy
*/
import * as myInterface from "@root/common/interface/interfaces";
...
I want to have the comment header at the very top of ...
4
votes
1
answer
164
views
How to use JSDoc to document a Vue component with script setup?
I'm building a Vue library with TypeScript. I'd like to export the documentation of the components, like I do with ordinary functions.
Previously we would do this:
<script>
/**
* This is the ...
0
votes
1
answer
15
views
How can I document randomly-assigned properties of a custom type in JSDoc?
/**
* @typedef {string} UUID
* */
/**
* @typedef {Object} ITEM
* @property {UUID} id
* */
/**
* @typedef {Object} THINGY
* @property {??????}
* */
const oneThingy = {
asdf: {id: 'asdf', .....
0
votes
2
answers
85
views
typings support for createAsyncThunk generated action creators and params
I was following along with the Redux Essentials Tutorials on how to employ createAsyncThunk for generating Thunks. In their example here they create a thunk like so:
export const addNewPost = ...
0
votes
1
answer
26
views
How to document a class as member of namespace
// in some file
/**
* @typedef myspace
* @property {Object} models
* @property {Object} services
*/
// in other files
/** @typedef myspace.models.ModelA */
class ModelA { ... }
/** @typedef ...
0
votes
0
answers
21
views
Javascript inheritance and JSDoc - let base class know about type defined in derived class
Using JSDoc, is it possible to let a base class know about a param type defined in a derived class in javascript?
For example:
class ServiceBase {
constructor(repository) {
this.repository = ...
1
vote
1
answer
128
views
How to document function custom types in JSDoc (or TypeScript?) and reference them so VSCode IntelliSense works
I am trying to document custom function types as part of an object, any help would be greatly appreciated:
Context of the problem
Here is a simple object declaration with some function properties (...
0
votes
1
answer
58
views
jsdoc fails to run and complains about an unexpected token
I have a simple test program
(docs) [dsargrad@sdbie-sargrad test]$ cat main.js
/**
* A person generator
*
* @param {string} name The persons full name
* @param {number} age The persons age
* ...
1
vote
1
answer
90
views
JSDoc Promise multiple resolve types
I have a promise that I am trying to document using JSDoc. It has three resolve types, string[], Object[] and Object. There seems to be a number of ways suggested to document this but I can't seem to ...
0
votes
0
answers
31
views
jsdoc include/add additional static files/pages like html/markdown
I know there is way to copy static files via jsdoc, for images as example.
Is there a way to "extend" the generated template via markdown or html files that integrate into the "look &...
0
votes
0
answers
18
views
VSCode hashmap autocomplete is not working
I am not sure where I did wrong.. This below is my code.
type.d.ts:
type _MaterialTable = {
weight: number
price: number
}
type Material = {
[index: string]: _MaterialTable
}
test.js:
/** ...
5
votes
2
answers
84
views
jsdoc to auto use description field
I have an object like this:
resource.foo= {
name: "Foo",
desc: "Some description"
}
I find myself writing:
/**
* Some description
*/
resource.foo= {
name: "Foo",
...