JSDoc
- https://github.com/Microsoft/TypeScript/wiki/JsDoc-support-in-JavaScript
- webpack 的代码库使用 JSDoc 并通过 TS 进行 lint https://twitter.com/TheLarkInn/status/984479953927327744(一些疯狂的黑客:https://twitter.com/thelarkinn/status/996475530944823296)
- 如果使用 closure-compiler,JSDoc 可以进行类型检查 https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System
需要注意的问题
object
由于某种原因被转换为any
。- 如果 JSDoc 中存在错误,您不会收到任何警告/错误。TS 只是默默地不为函数添加类型注释。
- 强制转换可能很冗长
(感谢 Gil Tayar 和 Gleb Bahmutov 分享以上评论)