I'm currently writing an interface
which works alright, but is verbose. Declaring types in this manner adds around n+3 lines of code (n = number of props) and I tend to look up and down at the interface
multiple times when working on this file, since the types are declared away from where the props are being destructured.
Using an interface:
interface MyComponentProps {
name: String;
type: String;
minLength?: Number;
maxLength?: Number;
}
function MyComponent({
name = "",
type = "text",
minLength,
maxLength,
...props
}: MyComponentProps) {
return null;
}
I'm simply wondering if there's a way to declare types next to where the props are destructured, such as:
Destructured types?
function MyComponent({
name, (String)
type, (String)
minLength, (Number?)
maxLength, (Number?)
...props (any?)
}) {
return null;
}
I apologize if this is obvious or has been asked previously, but I'm new to TypeScript and wasn't able to find any answers that didn't essentially just say: "Use an interface"