-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Component prop rejects my component in TypeScript #19536
Comments
Seems to be an issue with more than just the Here's a sandbox with my code showing the similar issue. If I were to update the type definitions for import * as React from 'react';
import { TypographyProps } from '../Typography';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
export interface CardHeaderTypeMap<P = {}, D extends React.ElementType = 'div'> {
props: P & {
action?: React.ReactNode;
avatar?: React.ReactNode;
disableTypography?: boolean;
subheader?: React.ReactNode;
subheaderTypographyProps?: Partial<TypographyProps>;
title?: React.ReactNode;
titleTypographyProps?: Partial<TypographyProps>;
}
defaultComponent: D;
classKey: CardHeaderClassKey;
}
declare const CardHeader: OverridableComponent<CardHeaderTypeMap>;
export type CardHeaderClassKey =
| 'root'
| 'avatar'
| 'action'
| 'content'
| 'title'
| 'subheader';
export type CardHeaderProps<
D extends React.ElementType = CardHeaderTypeMap['defaultComponent'],
P = {}
> = OverrideProps<CardHeaderTypeMap<P, D>, D>;
export default CardHeader; |
I could push out a change, looks like it'll be of the same flavor as this PR. |
@theGirrafish Thanks for the effort in #20110, we are getting closer to full coverage of the |
However, the last time I have checked, the approach isn't compatible with hosting the prop's description in TypeScript nor with the |
For what it is worth, I rewrote my uses to make my trigger component into a button, then route the clicks onto the Collapse.in property. Slightly less elegant IMO, but functionally equivalent to what I wanted. This doesn't invalidate the typescript issues when you actually want to use the component property though. |
Thanks for the report.
This is expected behavior since TypeScript improved their error message so it may be a bit more clear now:
|
I am using the Collapse component in a TypeScript project.
I am trying to set a custom trigger component for the Collapse component, using the component prop. This works if the component is a dumb one, but not if it requires props. I want a collapse trigger that is dynamically generated such that it can show a summary of the collapsed contents.
Current Behavior 😯
I get the following error
Expected Behavior 🤔
I would expect that my component works as if it was JS instead of TypeScript, or some documentation for the Collapse component stating how I should typify my component. I only found a general reference to create an issue here if I were to find such a rejection though, so here I am. Also seems to be similar to issue #17699 that was fixed.
Steps to Reproduce 🕹
Here is a codesandbox showing the issue.
https://codesandbox.io/s/heuristic-lalande-plt53
Also a sandbox to show that it is not an issue in JS.
https://codesandbox.io/s/material-demo-6j9ef
Steps:
1 The error is directly visible in the sandbox.
Context 🔦
I am trying to have a dynamic Collapse trigger.
Your Environment 🌎
The text was updated successfully, but these errors were encountered: