Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include Flow Types into JSDoc

I've been reading some issues on github and projects built on top of Flow for creating 'a bridge' between Flow and JSDoc or for simply generating JSDoc from Flow types annotation.

None of them answered this "simple" need I have:
Q: How to include Flow types into JSDoc?

I don't want to get rid of JSDoc comment blocks because they are not only meant for type checking but also for documentation and explaining the code to others or your future self.

What I want is this:

// @flow
// This file should be parsed by flow   

// 1) Use all the advantages of flow
type MyObject = {
  foo: number,
  bar: boolean,
  baz: string,
}; 

// later..

// 2) Comment AND annotate FLOW TYPE using JSDoc, not the Flow syntax
/**
 * Make super complex thing
 * @param {MyObject} val an object of type MyObject
 * @returns {String} an interesting value
 */
function superComplexThingy(val) { 
  return val.baz  
}

To summarise, I'd like to:

  1. Use all the advantages of flow (like the type definition above)
  2. Comment AND annotate FLOW TYPE using JSDoc, not the Flow syntax

Is this possible? How?

like image 438
Leonardo Avatar asked Aug 05 '26 03:08

Leonardo


1 Answers

Super late response, but this isn't something that's supported by Flow, and it likely will not be supported. If you want to write your own transpiler to convert some jsdoc comments to Flow types, you might be able to do it, but it would take a lot of work.

Some others have attempted work on this sort of thing, but it doesn't seem too active: https://github.com/Kegsay/flow-jsdoc

like image 57
James Kraus Avatar answered Aug 06 '26 18:08

James Kraus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!