I am creating a stream as :-
var stream = fs.createWriteStream("filepath");
Now, I am passing this as argument to a function. When writing the JSdoc for this method, I am not sure what would be its type. So, can someone tell me what would be its type in JSdoc?
JSDoc is a markup language used to annotate JavaScript source code files. Using comments containing JSDoc, programmers can add documentation describing the application programming interface of the code they're creating.
JSDoc's purpose is to document the API of your JavaScript application or library. It is assumed that you will want to document things like modules, namespaces, classes, methods, method parameters, and so on. JSDoc comments should generally be placed immediately before the code being documented.
You can use most JSDoc type syntax and any TypeScript syntax, from the most basic like string to the most advanced, like conditional types.
This is kind of a late answer but I recently encountered a similar problem.
The object returned by fs.createWriteStream
is of type WriteStream
as described by the API Reference of Node
You can use import in jsDoc @type
as follows.
const fs = require('fs');
/**
* Some definition explaining what this constant is
* @constant
* @type {import('fs').WriteStream}
*/
const stream = fs.createWriteStream("filepath");
I found about it here.
In my case, I was reusing the WriteStream
file multiple times so I used a combination of @typedef
and @type
/**
* @typedef {import('fs').WriteStream} WriteStream
*/
const fs = require('fs');
/**
* Some definition explaining what this constant is
* @constant
* @type WriteStream
*/
const stream = fs.createWriteStream("filepath");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With