【发布时间】:2021-06-09 19:14:09
【问题描述】:
我正在开发一个 React 应用程序。您可能知道,很多时候我们希望子组件的 props 直接链接到父组件的状态。
因此,我在父类组件的状态接口中添加了以下文档。
// Parent.tsx
interface ParentState {
/**
* Stores the list of errors encountered during render.
*/
errors: string[];
}
export function Parent extends React.Component<{}, ParentState> {
// ...
render () {
return <Child errors={errors} />
}
}
在单独文件中定义的子组件内,我希望ChildProps 接口共享相同的文档。
// Child.tsx
interface ChildProps {
/**
* How do I use the `ParentState.errors` definition?
*/
errors: string[]
}
export function Child (props: ChildProps) {
return <ul>{errors.map(error) => <li key={index}>error</li>}</ul>
}
我已经尝试使用 JSDoc @borrow module:Parent.ParentState.errors 标记,同时为 Parent 组件指定 @module Parent。我不知道如何链接这两个文档。无论我尝试什么,孩子道具的文档都不会显示在 VSCode 智能感知中。
我的问题是:如何从外部接口属性借用文档?
【问题讨论】:
标签: reactjs typescript jsdoc