GithubHelp home page GithubHelp logo

relationship with JSDoc? about flow HOT 25 CLOSED

facebook avatar facebook commented on April 20, 2024
relationship with JSDoc?

from flow.

Comments (25)

glukki avatar glukki commented on April 20, 2024 24

IMO, it would be great if Flow could take into account JSDoc declarations.
Because JSDoc already has semantics for user-types and arguments definition.

from flow.

davidrapin avatar davidrapin commented on April 20, 2024 22

@nmn the fact that you believe that "type information doesn't belong in JSDoc" might not be relevant here.
Most JS projects use JSDoc for type annotation, because that's how you get your IDE to become helpful. That's just a fact, things are done that way, whether we think its the right way or not.

The TypeScript complier added the ability to parse JSDoc annotation some time ago, and it makes a lot of sense: pure JS projects that had JSDoc type annotations are now able to be validated by the TypeScript compiler. That's a huge step forward.

It would be great to see Flow do the same.

from flow.

cameron-martin avatar cameron-martin commented on April 20, 2024 15

I think it would be useful to have a tool to generate/augment JSDoc annotations using flow's typechecker, rather than doing it the other way round. This way, documentation could be generated using JSDoc's documentation generator, but using flow's way more reliable type information.

from flow.

cletusw avatar cletusw commented on April 20, 2024 5

@avikchaudhuri Perhaps this needs to be reopened since #3 has been merged and closed, but without JSDoc support.

from flow.

tonygentilcore avatar tonygentilcore commented on April 20, 2024 4

I was looking for something similar and stumbled upon https://github.com/Kegsay/flow-jsdoc . Thought I'd leave it here in case it's useful to anyone.

from flow.

jedwards1211 avatar jedwards1211 commented on April 20, 2024 2

The thing that frustrates me is that the syntax for @param types in JSDoc is different than in Flow. I'd rather be able to put Flowtype types in my JSDoc, or that someone create a new documentation format altogether that's based upon Flowtype.

from flow.

avikchaudhuri avatar avikchaudhuri commented on April 20, 2024 1

Good idea, will look into this.

from flow.

StoneCypher avatar StoneCypher commented on April 20, 2024

They are effectively unrelated.

Flow scans your source and looks for type errors that it knows aren't right. For example, if you make a function which does arithmetic, then pass a string to said function, flow will notice that.

from flow.

briandipalma avatar briandipalma commented on April 20, 2024

It would be nice if JSDoc was parsed by flow and used as means to fill out type annotations for code that is missing them. It would help if there was a standard JSDoc format, I think the last time this was brought up at TC39 it was deemed not something that they should look at.

Maybe if tools like flow decided on one then other tools will standardize around it.

from flow.

Raynos avatar Raynos commented on April 20, 2024

It should be strongly noted that the semantics of JSDoc type system and flow type system are different.

Even if you can parse JSDoc, you may end up with ambiguity or with the problem that JSDoc cannot express enough information to get flow to check properly.

from flow.

avikchaudhuri avatar avikchaudhuri commented on April 20, 2024

Merging with #3

from flow.

ianwsperber avatar ianwsperber commented on April 20, 2024

I agree with @cletusw that this issue should be reopened. Being able to use comments for flow types is very nice, but being able to use JSDoc syntax would make flow easily available to existing codebases. Also I still like writing JSDocs to document my functions regardless of the typing benefit, so it seems like it would be duplicate work to have both comment types.

from flow.

StoneCypher avatar StoneCypher commented on April 20, 2024

Please read the merged ticket. Jsdoc docblock comments are explained there. They went with flowtate instead.

from flow.

mhagmajer avatar mhagmajer commented on April 20, 2024

There is also a problem that JSDoc won't event generate docs for code with flow annotations.

from flow.

nmn avatar nmn commented on April 20, 2024

@jedwards1211 I think a proper flow-types codebase and the gen-flow-files command can just replace JSDoc altogether for types.

And, Documentation.js understands Flow so we shouldn't need JSDoc at all.
https://github.com/documentationjs/documentation/blob/master/docs/GETTING_STARTED.md#flow-type-annotations

from flow.

jedwards1211 avatar jedwards1211 commented on April 20, 2024

@nmn ah, cool. Though last I tried gen-flow-files/read about it in the changelog it was a pretty buggy, preliminary implementation.

from flow.

nmn avatar nmn commented on April 20, 2024

@jedwards1211 Yeah gen-flow-files is still experimental, but at least its being worked on. I don't think JSDoc understanding has as much utility. Using JSDoc to add types is way less expressive than using Flow. At best, Flow should just treat leading comments before Functions as documentation. The type information doesn't belong in JSDoc.

from flow.

StoneCypher avatar StoneCypher commented on April 20, 2024

@jedwards1211 - documentation.js has native support for flow notation

from flow.

jedwards1211 avatar jedwards1211 commented on April 20, 2024

@davidrapin that's cool, but I bet there ended up being a lot of accidental errors from that approach? Because I would assume the types in a lot of JSDoc, being unchecked by a tool like Flow or TypeScript, tend to have a lot of mistakes...

from flow.

davidrapin avatar davidrapin commented on April 20, 2024

@jedwards1211 Indeed, very good point. It induced some JSDoc-cleanup sessions on projects I'm involved with, but nothing we couldn't manage. It was worth it!

from flow.

sobolevn avatar sobolevn commented on April 20, 2024

In my point of view, the most useful workflow is:

  1. Conditionally parse jsdoc for types (off by default)
  2. Generated stubs for this file with the parsed types
  3. User can modify these stubs as usual

What advantages I see here:

  • Possibility to fix wrong types declared in the docs
  • Nothing will break by default (as it should not break because of the comments)
  • We can still use existing type information

Do you see any cons in this solution?

from flow.

jedwards1211 avatar jedwards1211 commented on April 20, 2024

@davidrapin also, IDE support for flow type information was just behind relative to JSDoc because JSDoc came earlier. I'm pretty sure that WebStorm already understands flow types just as well as JSDoc, though I'm not sure. So JSDoc won't be the most ideal tool for IDE comprehension for long.

I think what @nmn means is that types for typechecking purposes don't belong in JSDoc.

from flow.

StoneCypher avatar StoneCypher commented on April 20, 2024

What they're talking about is pulling the flow types into the docs so that humans can read them, not so that the documentation checker can evaluate them

it's so that we don't have to type * @param foo {type} - bar when that's already known

from flow.

jedwards1211 avatar jedwards1211 commented on April 20, 2024

@StoneCypher I was referring to what David said, which I think other folks are advocating against:

The TypeScript complier added the ability to parse JSDoc annotation some time ago, and it makes a lot of sense: pure JS projects that had JSDoc type annotations are now able to be validated by the TypeScript compiler. That's a huge step forward.
It would be great to see Flow do the same.

from flow.

StoneCypher avatar StoneCypher commented on April 20, 2024

My response quite clearly expresses an understanding of that.

The reason that basically every documentation generator except this one supports at least one of the type systems at this point is that nobody wants to duplicate that information for their documentation.

Please re-read what I said to you, @jedwards1211. People should not be pushing back against this based on a faulty understanding of what's being requested.

There is a reason that every other documentation generator does this.

from flow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.