| 56 | }; |
| 57 | |
| 58 | function filterProps<T extends Record<string, unknown>, TKeys extends keyof T>( |
| 59 | asIs: boolean, |
| 60 | props: T, |
| 61 | omitKeys: TKeys[] |
| 62 | ): Partial<Omit<T, TKeys>> { |
| 63 | const filteredProps = omit(props, omitKeys) as Partial<T>; |
| 64 | |
| 65 | if (!asIs) { |
| 66 | /** |
| 67 | * A failsafe check for esModule import issues |
| 68 | * if validAttr !== 'function' then it is an object of { default: Fn } |
| 69 | */ |
| 70 | const interopValidAttr = |
| 71 | typeof validAttr === 'function' ? { default: validAttr } : validAttr; |
| 72 | |
| 73 | Object.keys(filteredProps).forEach((key) => { |
| 74 | if (!interopValidAttr.default(key)) { |
| 75 | // Don't pass through invalid attributes to HTML elements |
| 76 | delete filteredProps[key]; |
| 77 | } |
| 78 | }); |
| 79 | } |
| 80 | |
| 81 | return filteredProps; |
| 82 | } |
| 83 | |
| 84 | const warnIfInvalid = (value: unknown, componentName: string) => { |
| 85 | if (process.env.NODE_ENV !== 'production') { |