-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
If your components Props interface extends another interface, defaultProps still doesn't work in TS3 #61
Comments
ok what do you recommend i put in the cheatsheet? |
No idea! It might just be worth noting it in the bit about defaultProps
…On Sat, 5 Jan 2019 at 02:34, swyx ***@***.***> wrote:
ok what do you recommend i put in the cheatsheet?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#61 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAK-LrsR1n3FKH5p8CPl82hP14sWMXikks5vAA9EgaJpZM4Zp2gP>
.
|
have you reported this as a bug? (is this a bug? i think it is?) |
I actually haven't reported it as a bug yet, the bug reporting process was
a bit to in-detail and I wasn't sure where to put it!
…On Sun, 6 Jan 2019 at 13:12, swyx ***@***.***> wrote:
have you reported this as a bug? (is this a bug? i think it is?)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#61 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAK-Lkl7ymq6KBmFdEqUicKq-pYFvUiqks5vAfZUgaJpZM4Zp2gP>
.
|
just try :) good luck |
Do you have a code example for this? I would also open this as an issue in the DefinitelyTyped repo instead so the other React types maintainers can take a look. |
I guess it goes like type ComponentProps<T> = T extends React.ComponentType<infer P> | React.Component<infer P>
? JSX.LibraryManagedAttributes<T, P>
: never;
interface IProps {
name: string;
}
interface IDefaultProps {
age: number;
}
const GreetComponent = ({ name, age }: IProps & IDefaultProps) => (
<div>{`Hello, my name is ${name}, ${age}`}</div>
);
const defaultProps: IDefaultProps = {
age: 25,
};
GreetComponent.defaultProps = defaultProps;
// later
const TestComponent = (props: ComponentProps<typeof GreetComponent>) => {
return (
<div> <h1 /> </div>
);
};
const el = <TestComponent name="foo" />; |
thanks for the input @infctr! i dont quite see the point of TestComponent.
this seems correct behavior. @gausie, can we please see an example that you expect to work? otherwise its very hard to discuss. |
@sw-yx My point is (and that's my understanding of @gausie problem) type Props = React.ComponentProps(typeof GreetComponent) // all props are required
type Props = ComponentProps<typeof GreetComponent> // using helper, defaulted props are optional Extracting props with Consdider this interface Props extends ComponentProps<typeof GreetComponent> {
title: string;
}
const TestComponent = ({ title, ...props }: Props) => {
return (
<>
<h1>{title}</h1>
<GreetComponent {...props} />
</>
);
};
// age is optional on an inner component's props interface
const el = <TestComponent name="Johnny 5" title="foo" />; Just thought it was worth mentioning as it was not immediately obvious |
That's correct. There are valid use cases for extracting both the inner props of a component, or the apparent props (with |
hoo boy. ok. thank you |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions! |
No description provided.
The text was updated successfully, but these errors were encountered: