将流类型包含到 JSDoc 中 [英] Include Flow Types into JSDoc
问题描述
我一直在阅读 github 上的一些问题和projects 建立在 Flow 之上,用于在 Flow 和 JSDoc 之间创建桥梁",或者简单地从 Flow 类型注释生成 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.
他们都没有回答我这个简单"的需求:
问:如何在 JSDoc 中包含 Flow 类型?
None of them answered this "simple" need I have:
Q: How to include Flow types into JSDoc?
我不想摆脱 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.
我想要的是这个:
// @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
}
总而言之,我想:
- 利用流的所有优点(如上面的类型定义)
- 使用 JSDoc 而非 Flow 语法对 FLOW TYPE 进行注释和注释
这可能吗?怎么样?
推荐答案
响应超级迟,但这不是 Flow 支持的,而且很可能不会得到支持.如果你想编写自己的转译器将一些jsdoc注释转换为Flow类型,你也许可以做到,但需要大量的工作.
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.
其他一些人已经尝试过此类工作,但似乎不太活跃:https://github.com/Kegsay/flow-jsdoc
Some others have attempted work on this sort of thing, but it doesn't seem too active: https://github.com/Kegsay/flow-jsdoc
这篇关于将流类型包含到 JSDoc 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!