Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types of PlaceholderProps['fields'] incorrect #2042

Closed
st3phan opened this issue Feb 12, 2025 · 0 comments · Fixed by #2043
Closed

Types of PlaceholderProps['fields'] incorrect #2042

st3phan opened this issue Feb 12, 2025 · 0 comments · Fixed by #2043
Labels

Comments

@st3phan
Copy link
Contributor

st3phan commented Feb 12, 2025

Describe the Bug

When using the withPlaceholder HOC I'm extending the props type of the wrapped component with PlaceholderComponentProps.

type ComponentProps = PlaceholderComponentProps & {
  fields: ComponentRendering["fields"];
  items: ReactNode;
};

const Component = () => {
  // ...
};

export default withPlaceholder("items")(Component);

But then TypeScript complains about the fields type being incompatible.

The current type for the fields property in the PlaceholderComponentProps interface:

export interface PlaceholderProps {
  ...
  fields?: {
    [name: string]: Field | Item[];
  };
 ...
}

The type does not match the ComponentFields interface:

export interface ComponentFields {
    [name: string]: Field | Item | Item[];
}

To Reproduce

Extend rendering component props type with PlaceholderComponentProps.

Expected Behavior

I believe the type for the fields property in the PlaceholderProps should be:

export interface PlaceholderProps {
  ...
  fields?: {
    [name: string]: Field | Item | Item[];
  };
}

This way they match the ComponentFields interface.

Possible Fix

No response

Provide environment information

  • JSS Version: 22.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant