Yozi is right but there is another way, which demonstrates a typescript (and general FP) feature which you may not be familiar with if you're coming from something like C# or Java.
interface MyCustomProps {
customProp: string;
}
const MyComponent = (props: MyCustomProps & React.HTMLAttributes<...>)
=> (...)
In typescript, an &
in a type declaration refers to an intersection type. You can read more in the typescript docs. The props
object now combines the properties of MyCustomProps
and the HTML attributes. (It's also worth learning about discriminated unions, or or
types, which are notated with |
. I find these more useful than intersections).
If you want to clean up your method signature, you could declare the type as follows:
interface MyCustomProps {...}
type ComponentProps = MyCustomProps & React.HTMLAtributes<...>;
However, this notation has now lost the conciseness of both the previous approaches - the extends
syntax, and the &
notation.