Within my application, there is a grid component that serves multiple purposes and handles different types of data.
Each type of data is fetched from various API endpoints with unique filtering options, all properly defined with appropriate types. Everything functions well when dealt with individually.
Is there a way to categorize all these diverse data types under a common "family" grouping?
I envision defining the structure of a family, specifying its elements (like Filter type, Response type, etc.), and enforcing relationships (e.g., requiring a specific filter type for a certain data type).
I've experimented with interfaces and classes but encountered limitations in specifying types containing special characters like '.' which are reserved for namespaces.
Although promising, namespaces do not allow me to enforce the required structure, preventing me from utilizing a universal "abstract" namespace within my component.
Any suggestions on how I should approach this dilemma?
EDIT: To clarify, here's my objective:
type View<D, F> = {
// actual types required, not instances
Data: D;
Filter: F;
}
type TasksView = View<Task, TaskFilter>;
type ProjectsView = View<Project, ProjectFilter>;
interface GridProps<T extends View> {
filters: T.Filter;
}
function Grid<T>(props: GridProps<T>) {
const getData(props.filters): T.Data {
// fetch data
}
return (
<table>
</table>
)
}
function MyTasksGrid = Grid<TasksView>
function MyProjectsGrid = Grid<ProjectsView>
This may not be entirely syntactically accurate, but it demonstrates the idea. Essentially, I aim to establish a connection between the Task
and TaskFilter
types through a shared structure.
However, the use of T.Data
as outlined isn't feasible due to T not being recognized as a namespace (
'T' only refers to a type, but is being used as a namespace here
).