Answer the question
In order to leave comments, you need to log in
Where to place closely related typescript types?
For example, there is a structure such a structure of components:
/Grid
Grid.tsx
GridItem.tsx
type GridItemProps = {
title: string;
description: string;
}
type GridProps = {
title: string;
items: Array<GridItemProps>;
}
Answer the question
In order to leave comments, you need to log in
On a good note, the new type should be used here, not the existing GridItemProps.
Declare 1 more GridItem that will have the desired set of properties
Do not listen to Vasily Bannikov , you definitely don’t need to produce copy-paste types.
And in terms of the placement of types, the logic is exactly the same as with ordinary modules. So it's perfectly fine to import related types from a related module. All theories and design patterns apply here.
For good, of course, you should stick to SOLID or something like that.
Those. to Grid
make a type IGridItemProps
with those properties that are exactly needed for work Grid
, and to GridItem
inherit from it already a specific implementation
interface GridItemProps extends IGridItemProps { ... }
. However, this is only necessary if, theoretically, more GridItemSuper
and can appear GrigItemNice
, but if this cannot be and the modules (components) themselves are closely connected, then you should not bother.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question