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,698
questions
0
votes
1
answer
25
views
eslintrc type-safety in VSCode using jsdoc annotations importing typescript declarations
How do I get VSCode to check syntax of .eslintrc.js and do autocompletion ? I was able to use the following structure for a js config file that follows a custom syntax defined by my own app, but when ...
0
votes
1
answer
36
views
Get rid of repetitive JSDoc type declarations in object literal
While my question is more general and not directly related to automation tests architecture, POM, and any framework I will use some real-world examples.
In my test framework I use Cypress and POM ...
1
vote
1
answer
32
views
How do you get the return type of a function in jsdoc?
I have two files src/a.js src/b.js.I want the type of response to be the return value of the request function.
If in Typescript I could have written this ⬇️。Is there a similar syntax in jsdoc?
I don'...
0
votes
0
answers
22
views
JSDoc: How to Document Custom Properties and Methods in Express Request and Response Objects in nodejs?
I'm working on an Express.js project in JavaScript and would like to document custom properties and methods in the Express Response objects using JSDoc comments.
Specifically, I want to add a custom ...
0
votes
0
answers
19
views
How to override TSDoc/JSDoc from props that are common to multiple prop type definitions?
I'm building a React component (EmailHeader) with Typescript and I'm trying to define its props types. It receives some props directly from the parent (EmailEditor), and on the Props type declaration ...
0
votes
0
answers
72
views
how to use class in library with hints
I created a Google script without a container with this code and deployed it as a library.
/**
* @class
*/
class Table5 {
constructor(ss_id){
this.ss_id = ss_id;
}
/**
* GetSheet5
...
1
vote
1
answer
30
views
Properties defined in prototypal base-class's ctor are not identified as own props in a derived class
I'm documenting existing code with JSDoc in Eclipse with jsconfig.json configured (could add it here, but it mainly says "es2017", and path declarations that I saw perfectly working).
I'm ...
0
votes
1
answer
29
views
JavaScript JSDoc and Visual Studio Code: Document a function property properly
The TLDR version is: I want to document an external "class" in JavaScript using JSDoc where one of the properties is a function (method) with a named parameter and have it show up in Visual ...
1
vote
3
answers
89
views
In JSDoc, how can I document an object that takes both optional named properties of specific types and unknown properties
In my JavaScript module I have defined an object type in JSDoc that I use in a function:
//@ts-check
/**
* @typedef {Object} Person
* @property {number} age
* @property {string} name
*/
/**
* ...
0
votes
0
answers
9
views
Enable JSDoc intellisense on properties in unioned types?
If I write doc comments on a property in a TypeScript type, they show up when hovering the property.
If I make the type a more complex union type, the doc comments no longer appear.
I can get the ...
0
votes
0
answers
23
views
How to document the javascript class method using jsdoc?
Here is my JS class:
/**
* QQ object
* @date 8/16/2023 - 3:53:07 PM
*
* @export
* @class QQ
* @typedef {QQ}
*/
export default class QQ{
/**
* Creates an instance of QQ.
* @date 8/...
1
vote
1
answer
30
views
Handling a null-initialized object with the @ts-check option
I have enabled the quite useful // @ts-check option in VScode, but now I have no idea how to handle a null-initialized object.
Here is a simplified example:
// @ts-check
const settings = {
a: null,
...
1
vote
1
answer
29
views
JSDoc: where to put overloaded function description
Given the following overloaded function documented with JSDoc, where can I put the description of said function?
/**
* @overload
* @param {string} arg0
* @return {void}
*//**
* @overload
* @...
0
votes
0
answers
27
views
How to use JSDoc and ts-check with a vanilla JavaScript constructor that returns a value directly?
Using vanilla JavaScript, I want to code a constructor that creates its instances by returning an object instead of using this. As explained on MDN:
Normally constructors don't return a value, but ...
0
votes
1
answer
58
views
How to jsdoc constructor function returning a new object properly?
For example I have a code like this:
export { createPerson }
const createPerson = (name, age) => {
const getFullData = () => {
return `Person ${name} is ${age} years old`
}
return {
...
0
votes
1
answer
52
views
Declare a TypeScript enum in JSDoc
How does one use JSDoc @typedefs to declare a TypeScript enum in a .js file? (This is for a piece of legacy code that cannot yet be migrated to TypeScript, but needs to be imported into a TypeScript ...
0
votes
0
answers
13
views
SuiteScript: JSDoc for function from higher scope (define)
SuiteScript (2.x) wraps the script code in define function.
define(['N/task'], (task) => {
// my code
});
In my IDE (VSCode) is define underlined and shows following tooltip Cannot find name '...
0
votes
0
answers
18
views
Is there a way to use JSDoc's @alias in TypeScript?
Simplified version of my manually defined .d.ts file:
interface FooLikeInner<A, B> extends Foo<A, B> {}
declare global {
export namespace FooPackage {
// Foo comes from an ...
3
votes
1
answer
194
views
How to use jsdoc on vue3 props without typescript?
const props = defineProps({
items: {
/** @type {{new(): Color[] }} */
type: Array,
required: true,
},
selectedColor: {
type: Object,
required: true,
},
composable: {
...
0
votes
1
answer
32
views
Interaction of JSDoc and type mapping
I'm looking for a complete list (preferrably from a "reputable source") of information on how TypeScript's JSDoc works with types and their mappings and modifications.
The obvious basics are ...
0
votes
1
answer
16
views
jsdoc should be before class or constructor in javascript?
Im using a vscode (but should be the same in any code editor), and in the following code, when I hover over Circle, it shows me the contents of the jsdoc i've written, but doesn't show them when i ...
0
votes
1
answer
32
views
Unable to annotate a generic identity function with JSDoc
I expected the following to work:
// @ts-check
/**
* @template A
* @callback Identity
* @param {A} a
* @returns A
*/
/**
* @template A
* @type {Identity<A>}
*/
const id = (a) => a
/...
2
votes
1
answer
38
views
Syntax error in my JSDoc type when key is named "event"
Here is a jsdoc that the jsdoc plugin of eslint does not like:
@property {{event: Object.<string, MyEnum[]>, observation: Object.<string, MyEnum[]>}} enums
It complains: Syntax error in ...
0
votes
0
answers
15
views
Cascading function definition tooltips
I have a function that has a configuration object as a param, which has a function as one of its properties. I have defined the types with JSDoc with something like this:
/**
* @callback ...
1
vote
1
answer
44
views
How to use JSDoc to document and enforce typing for components composed with higher-order components
Let's imagine I have the following HOC in React 18+:
/**
* @param { LoadingCardProps } config
*/
export const withLoader = (config) => {
/**
* @template P
* @param { ReactComponent<P&...
0
votes
0
answers
27
views
getting blurred image thumbnails displayed on shaka player?
I'm using shaka player latest version to as a player in my app. I'm trying to display the thumbnail images while seeking on the player progress bar. But when I seek forward/rewind on the player ...
0
votes
0
answers
17
views
How does VSCode use JSDoc to generate smart hints?
Does anyone know where I can find where VSCode has all these "hints" about native features in JS so I can do similar things with them?
Notice how it tells me in the image below information ...
1
vote
0
answers
28
views
With JSdoc How can I make an object type returned dynamically depending of a the parameter?
Hi i need to define a type returned dynamically depending of the parameters.
This is my actual code with jsdoc
/**
* @param {Array<string>} columns
* @return {Promise<Array<Object>>...
0
votes
0
answers
23
views
Detect global types in VS Code with raw JS
I have two folders with JS sources which export Classes that are available globally and have JSDoc comments. Is it possible to have VS Code recognize these globally without...
Maintaining seperate TS ...
2
votes
0
answers
38
views
How to write a JSDoc code to prevent unwanted property to be added into an object
/**
* @typedef {object} User
* @property {number} id
* @property {string} name
*/
/**@type {User} */
let user
user.phoneNo = '123456' // Should give an Error
if not ...
0
votes
0
answers
31
views
How to tell JSdoc argument is optional
I want to pass to a method either a String or nothing.
My JSDoc looks like this:
/**
* Explain...
* @param {String|undefined} someVar
*/
runMethod(someVar) {}
I call the method either with an ...
0
votes
1
answer
62
views
Why doesn't TypeScript warn when a function is used with a different number of arguments as expected?
I have a vanilla JavaScript project in VS Code with jsconfig.json set up and the following example code:
/**
* @param {(arg: string) => void} nestedFunction
*/
function myFunction(nestedFunction) ...
0
votes
0
answers
51
views
Explicitly Set Types on express.js IRouterMatcher
Referencing the answers on How to annotate Express middlewares with JSDoc?, there are answers on how to add types to express methods with JSDoc. They all generally give a way to type your handlers ...
0
votes
0
answers
59
views
Vue packages version mismatch when trying to use @component plugin from better-docs
I want to add jsdoc to my vue project after adding @component plugin from better-docs. I face error.
Error message:
`
Vue packages version mismatch:
[email protected] (C:\Users\patre\OneDrive\Pulpit\Work\...
0
votes
1
answer
18
views
How to make different type for a JavaScript Class in JSDoc?
I want to do something like Map<string, number> and Map<string, string> using JSDoc without TypeScript. How?
class MyValue {
setValue(value){
this.myValue = value;
}
getValue(){
...
0
votes
0
answers
38
views
Save JSDOC comments of React components in Webpack build
I am developing a library of React components. Libraries versions: react - 17, webpack - 4. I encountered difficulties when building a package of React components through Webpack 4 with mode="...
0
votes
0
answers
23
views
Generate JSDoc for ES5-style methods?
I am writing some JS scripts for a tiny JS interpreter that only supports ES5 and earlier syntax. For an object with methods, I can't use the "class" keyword, but can only do it in the ...
2
votes
0
answers
45
views
How to specify the generic type of a funcion call in jsdoc when parameters can't infer type
I'm trying to use JSDoc for typings, and i came across this scenario (this is a simplified example).
We can use @template for generics, and parameters can make it infer the type of return like this ...
0
votes
0
answers
29
views
How to add deprecation notice to multiple destructured variables?
I need to add deprecation notice to multiple (up to 100) variables using JSDoc. Is it possible to do so without repeating the same notice 100 times?
My code looks like this:
/**
* @deprecated
* Those ...
3
votes
1
answer
55
views
Preserve key/values for autocomplete after deep merge in JavaScript
I'm writing a rather minimalistic config system. The idea is having a config.template.js and a config.custom.js. Now, all set values from custom should override those in template. Values missing from ...
0
votes
0
answers
35
views
WebStorm creates method in the wrong place
When the instance of foo is initialized inline, it infers even without JSDoc that the method to add belongs to Foo.
By clicking enter, this results in the expected result:
class Foo {
...
2
votes
1
answer
39
views
How to describe an object type that can have additional properties apart from specific ones?
I have a data type called User currently, and I want it to have two mandatory properties, name and age. In addition, users should be able to add any number of other properties to it. How should I ...
1
vote
0
answers
45
views
JSDocs for Mongoose Schemas, including the implicit _id field
I want to be able to have JSDoc understand Mongoose Schemas so I can use the types in @param, @returns, and @type. I managed to achieve that using this question. This works great:
/**
* @class ...
1
vote
0
answers
22
views
Add type hint for function to limit this in typescript [duplicate]
let f = function () {
this.aa += 1;
}
class A {
constructor(f) {
this.aa = 1;
f.call(this);
console.log(this.aa);
}
}
new A(f)
how could I write a type definition ...
0
votes
0
answers
55
views
JSDoc Types for Runtime Validation
We are currently considering adding JSDoc with typing / type safety to our projects. We favor JSDoc with types over Typescript because we write mostly self-contained functions and don't want the ...
2
votes
3
answers
430
views
How to infer Zod type in JSDoc (without TypeScript)
Suppose I have the schema in javascript:
import {z} from "zod";
let personSchema = z.object({
name: z.string(),
id: z.number()
});
now I want to use the type somewhere else:
/**
* @...
1
vote
0
answers
19
views
Directory scoped typedef files and exported modules that implement their types
I've imported and defined a type Match over the directory foo by adding it to a typedef.js file in foo's root.
A function exported from foo which passively uses that type is imported in bar.js in ...
0
votes
1
answer
59
views
How do I get the JSDoc text (docstring) from a function inside the code in JavaScript?
Considering I have a simple function, I want to extract the JSDoc string inside the code and display it in the page, like so:
/**
* Represents a book.
* @constructor
*/
function Book(title, author) ...
0
votes
1
answer
43
views
Why does TS complain when composing generic functions with @type and not @param and @return?
Why does TS complain about this:
/**
* @template X
* @type {function(X): X}
*/
const identity1 = (x) => x;
/**
* @template X
* @type {function(X): X}
*/
const identity2 = (x) => identity1(...
0
votes
0
answers
50
views
Make "ts-check" and "jsdoc" know about types defined in an IIFE
"Exporting" a type from an old style js module.
How can I achieve ts-check and jsdoc compatibility when working with an old-style JavaScript module that selectively exports classes through ...