jsx-eslint/eslint-plugin-react

react/prop-types false positive “is missing in props validation” for extended component types

Open

#3,159 建立於 2021年12月15日

在 GitHub 查看
 (2 留言) (4 反應) (0 負責人)JavaScript (8,630 star) (2,797 fork)batch import
help wantedtypescript

描述

I’m building a component with antd-style subcomponent access. I.e. I want to be able to do <Columns><Columns.Block/></Columns>.

I made two attempts, both of which complained about “… is missing in props validation” once I replaced a bare FC<…> with something else:

By extending FC<…>:

const Block: FC<…> = (…) => …

export interface ColumnProps { … }
export interface ColumnsComponent extends FC<ColumnsProps> {
  Block: typeof Block
}
const Columns: ColumnsComponent = (…) => …
Columns.Block = Block

and inline:

const Block: FC<…> = (…) => …

export interface ColumnProps { … }
const Columns: FC<ColumnsProps> & { Block: typeof Block } = (…) => …
Columns.Block = Block

貢獻者指南

react/prop-types false positive “is missing in props validation” for extended component types · jsx-eslint/eslint-plugin-react#3159 | Good First Issue