patternfly / patternfly/react-topology
ComponentFactory return type is restricting
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 21
- Forks
- 27
- PR merge metrics
- No merged PRs in 30d
Description
Describe the problem
Due to how ComponentFactory type is declared, components must define generic types and then cast to specific types using as. For projects where type casting is not wanted, this causes an issue.
How do you reproduce the problem?
The ComponentFactory type is declared as:
export type ComponentFactory = (
kind: ModelKind,
type: string
) => ComponentType<{ element: GraphElement | Graph | Edge | Node }> | undefined;
This has a side effect where components, even if they work with Edge, declare their type as element: GraphElement and then end up typecasting to their correct type as seen here: https://github.com/patternfly/react-topology/blob/main/packages/demo-app-ts/src/components/DemoDefaultEdge.tsx
I would expect to be able to define my edge component as:
type EdgeProps = {
element: Edge;
I believe this could be solved by updating the ComponentFactory type definition:
type ComponentFactory = (
kind: ModelKind,
type: string,
) =>
ComponentType<{ element: GraphElement }>
ComponentType<{ element: Edge }>
ComponentType<{ element: Node }>
ComponentType<{ element: Graph }>
undefined;
Expected behavior
A clear and concise description of the expected behavior.
Is this issue blocking you?
Not blocking. Continue to cast.
What is your product and what release date are you targeting?
RHOAI 2.11
Any other information?
Jira Issue: PF-2006
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Search the repository for the ComponentFactory declaration, then inspect packages/demo-app-ts/src/components/DemoDefaultEdge.tsx to understand the current cast. Verify how component types are selected for GraphElement, Edge, Node, and Graph, and confirm that edge components can use Edge without a cast while existing component behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100