首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >tsdoc-param-tag-with-invalid- name:@param块后面应该跟一个有效的参数名称(TypeScript、ESLint和React)

tsdoc-param-tag-with-invalid- name:@param块后面应该跟一个有效的参数名称(TypeScript、ESLint和React)
EN

Stack Overflow用户
提问于 2020-09-07 18:20:37
回答 1查看 262关注 0票数 0

我正在为TypeScript的React Native项目使用JSDoc和TSDoc。在记录道具时有一些奇怪的行为。

所有@param: props.propName都带有下划线,消息如下:

代码语言:javascript
复制
tsdoc-param-tag-with-invalid-name: The @param block should be followed by a valid parameter name: The identifier cannot non-word characterseslinttsdoc/syntax

另外,我还必须添加: Props两次,因为如果我只将它放在FC中,则props会被加下划线:

代码语言:javascript
复制
'onPress' is missing in props validationeslintreact/prop-types

代码:

代码语言:javascript
复制
import React, { useContext, FC } from 'react'
import { GestureResponderEvent, ViewStyle } from 'react-native'
import { useNavigation } from '@react-navigation/native'
import { UserAvatarContext } from '../apps'
import Avatar from './Avatar'

interface Props {
  size?: number
  radius?: number
  style?: ViewStyle
  onPress?: (event: GestureResponderEvent) => void
}

/**
 * Display the user profile avatar and link
 *
 * @param props - React props
 * @param props.size - the size of the avatar in pixels
 * @param props.radius - the border radius in pixels
 * @param props.onPress - the function to use when pressing the avatar (by default, navigate to the user profile page)
 * @param props.style - Additional style information
 * @returns The avatar icon
 */
const UserAvatar: FC<Props> = ({ size = 40, radius, style, onPress }: Props) => {
  const navigation = useNavigation()
  const { source } = useContext(UserAvatarContext)
  const defaultOnPress = (): void => navigation.navigate('My profile')

  return <Avatar source={source} onPress={onPress || defaultOnPress} size={size} style={style} radius={radius} />
}

export default UserAvatar

我希望它是干净的,但我觉得我需要做一些配置或修改声明我的道具的方式。有什么想法吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-07 20:14:57

只需将属性描述移动到接口定义,如下所示:

代码语言:javascript
复制
import React, { useContext, FC } from 'react'
import { GestureResponderEvent, ViewStyle } from 'react-native'
import { useNavigation } from '@react-navigation/native'
import { UserAvatarContext } from '../apps'
import Avatar from './Avatar'

interface Props {
  // the size of the avatar in pixels
  size?: number
  // the border radius in pixels
  radius?: number
  // Additional style information
  style?: ViewStyle
  // the function to use when pressing the avatar (by default, navigate to the user profile page)
  onPress?: (event: GestureResponderEvent) => void
}

/**
 * Display the user profile avatar and link
 *
 * @param props - React props
 */
const UserAvatar: FC<Props> = ({ size = 40, radius, style, onPress }: Props) => {
  const navigation = useNavigation()
  const { source } = useContext(UserAvatarContext)
  const defaultOnPress = (): void => navigation.navigate('My profile')

  return <Avatar source={source} onPress={onPress || defaultOnPress} size={size} style={style} radius={radius} />
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63775660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档