type OmitProps = | 'value' // 表单属性 | 'defaultValue' // 表单属性 | 'onChange' // 表单属性 | 'style' // 非 dom 属性 | 'className'; // 非 dom 属性 // 需要排除的属性 const omitList: OmitProps[] = [ 'value', 'defaultValue', 'onChange', 'style', 'className', ]; /** * 过滤掉非dom属性,同时过滤表单的受控属性 */ export function filterFormAndNonDomProps( props: T, ): Omit { const originDomProps = {} as unknown as Omit; if (typeof props === 'object' && props !== null) { Object.keys(props).forEach((key) => { if (!omitList.includes(key as OmitProps)) { originDomProps[key as keyof Omit] = props[key]; } }); } return originDomProps; }