-
Notifications
You must be signed in to change notification settings - Fork 66
Correct typings for themr
#39
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
Conversation
Hi.
It is happening because in definition of Thanks in advance and have great day! |
Can anybody confirm this update is properly done to merge? |
Just commited a fix. Let me know if it works @Podlas29. Only caveat is calling getWrappedInstance() won't return the type of the original component, it will return |
export function themr( | ||
identifier: string, | ||
defaultTheme?: {}, | ||
options?: IThemrOptions | ||
); | ||
): <P, S>(component: new() => React.Component<P, S>) => ThemedComponentClass<P, S>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still will not work if component accepts some props or context through constructor.
consturctor(props: MyProps) {}
Adding
new(props?: P, context?: any)
will help.
After that for me it works perfect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed. :)
Well I did get around all problems (both state type and wrong instance being returned in interface ThemedComponent<P, S, Base> extends React.Component<P, S> {
getWrappedInstance(): Base;
}
interface ThemedComponentClass<P, S, Base> extends React.ComponentClass<P> {
new(props?: P, context?: any): ThemedComponent<P, S, Base>;
}
export interface Themr {
(
identifier: string,
defaultTheme?: {},
options?: IThemrOptions
): <P, S, C extends new(props?: P, context?: any) => React.Component<P, S>>
(component: C) => ThemedComponentClass<P, S, C>;
} It got really ugly thought. ;) |
That's fine, it seems to be the only way to do it. I tried something like that but couldn't get it working. Thanks, updated with your code. Look good? |
One more thing - I just do not know - is it OK to pass stateless components to themr decorator? If so, I would add such possibility to typings. |
I'm not sure, - @javivelasco would have to confirm. However you can't even use decorators on functions; such as a stateless component. |
Well decorator is simply a function. In mobx for example you can use both
and
In our case it would be
Much cleaner if you do not need state. |
That's true, looking at the code I'm not sure if it would work with stateless components.. We'll have to see. |
@TheSBros Also my code seems problematic as well - typescript is unable to infer P and S and assumes they are |
@Podlas29 You can use the decorator in a functional component but the legacy syntax is valid only for classes. At the end it's just a function returning another function |
@javivelasco should be ready to merge now. Would recommend to squash to clean up the mess. |
Thanks! |
Seems like now there's a conflict with @themr('foo') //error - Type 'null' is not assignable to type 'Element'
class FooClass extends React.Component<any, any> {
render()/*: JSX.Element | null //ok when uncommented*/ {
return <div>hi</div>;
}
} |
Moreover, decorating a class with |
* refactoring * theme spreads * typings * fix themr typing * fix themr typing * fix undefined mixin value cases * fix state type incompatibility in #39 * revert typing changes * accept sfc as component * typo * also accept symbols and numbers as identifier * merge sfc fix
* Correct typings for `themr` * Fixed decorator usage * Update index.d.ts * Updated with better typings from @Podlas29 * Revert to working state
* refactoring * theme spreads * typings * fix themr typing * fix themr typing * fix undefined mixin value cases * fix state type incompatibility in javivelasco#39 * revert typing changes * accept sfc as component * typo * also accept symbols and numbers as identifier * merge sfc fix
No description provided.