简体   繁体   English

缺少 JSDoc @param "props.children" 类型。 和缺少 JSDoc @param "props.children" 类型。 使用 React Native FunctionalComponents

[英]Missing JSDoc @param "props.children" type. and Missing JSDoc @param "props.children" type. with React Native FunctionalComponents

I'm using JSDoc & TSDoc on a react native project.我在本机反应项目上使用 JSDoc 和 TSDoc。

Here is the file:这是文件:

import React, { createContext, useContext, FC } from 'react'
import useUserData, { UseUserDataType } from './useUserData'
import { AuthContext } from './FirebaseContextProvider'
import { AuthUser } from '../../common'

// Initial state

const initialUserDataContext = {
  userData: {},
} as UseUserDataType

// Create the context objects
export const UserDataContext = createContext<UseUserDataType>(initialUserDataContext)

/**
 * Context provider for user data from firebase
 *
 * @param props -
 * @param props.children - application parts that are dependent on user data.
 * @returns a context provider for user data
 */
const DataContextProvider: FC = ({ children }) => {
  const { user } = useContext(AuthContext)
  // UserData
  const userData = useUserData(user as AuthUser)

  return (
    <UserDataContext.Provider value={userData}>
          {children}
    </UserDataContext.Provider>
  )
}

export default DataContextProvider

I have two warnings:我有两个警告:

On the second @param:在第二个@param:

tsdoc-param-tag-with-invalid-name: The @param block should be followed by a valid parameter name: The identifier cannot non-word characterseslinttsdoc/syntax

On the begining of the JSDoc lines:在 JSDoc 行的开头:

Missing JSDoc @param "props.children" type.eslintjsdoc/require-param-type

I'm not really getting how I shall document the props I guess.我真的不知道如何记录我猜的道具。 Any insights?有什么见解吗?

Thanks谢谢

Edit:编辑:

If I add the types as @param {Type}, TSDoc complain because it is TypeScript:如果我将类型添加为 @param {Type},TSDoc 会抱怨,因为它是 TypeScript:

tsdoc-param-tag-with-invalid-type: The @param block should not include a JSDoc-style '{type}'eslinttsdoc/syntax

For the time being I deleted the rules, waiting to see if there is a better configuration.暂时把规则删了,等着看有没有更好的配置。

'jsdoc/require-returns-type': 'off',
'jsdoc/require-returns-type': 'off',

This might be a little old but for those who run into similar issues.这可能有点旧,但对于遇到类似问题的人来说。

Sheraff was right in the comment so I'd like to expand. Sheraff 在评论中是正确的,所以我想扩展一下。

Let's first look at the error/s:让我们先看看错误:

Missing JSDoc @param "props.children" type. 

So that means you are missing the parameters type.所以这意味着您缺少参数类型。

Then:然后:

tsdoc-param-tag-with-invalid-name: The @param block should be followed by a valid parameter name: The identifier cannot non-word characterseslinttsdoc/syntax

This means this:这意味着:

* @param props.children - application parts that are dependent on user data.

Should be this without text after the param name:应该是在参数名称后没有文本的:

* @param {Object} children

Then finally this:最后是这个:

tsdoc-param-tag-with-invalid-type: The @param block should not include a JSDoc-style '{type}'eslinttsdoc/syntax

This means you have added a type - {type} - which is not a recognised type.这意味着您添加了一个类型 - {type} - 这是一个不可识别的类型。 A valid type means String, Int, Object and this is NOT because you are using TS.有效类型表示 String、Int、Object,这不是因为您使用的是 TS。 It's JSDoc needs them signatured. JSDoc 需要他们签名。

So to fix I believe the below would do it:所以要修复我相信下面会做到这一点:

/**
 * Context provider for user data from firebase
 *
 * @param {Object} children
 * @returns a context provider for user data
 */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM