Answer the question
In order to leave comments, you need to log in
Is it possible to implement more elegant object typing and destructive assignment?
I caught myself constantly writing such and such strange constructions, repeating myself twice in the names of variables:
export const Component = ({
prop1,
prop2,
prop3,
}: {
prop1: string;
prop2: number;
prop3: boolean;
})=>{
//...
}
Answer the question
In order to leave comments, you need to log in
And for starters, come up with a syntax for this that would not enter into direct conflict with JS and at the same time be intuitive.)
Here , many copies are broken on the topic, but, IMHO, there are no normal release-worthy options. )
You can move the type of props to a separate type / interface
type ComponentProps = {
prop1: string;
prop2: number;
prop3: boolean;
}
export const Component = ({ prop1, prop2, prop3 }: ComponentProps) => {
...
}
export const Component: FC<ComponentProps> = ({ prop1, prop2, prop3 }) => {
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question