-
Notifications
You must be signed in to change notification settings - Fork 5
Add TypeScript types #30
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
base: master
Are you sure you want to change the base?
Conversation
interface Options { | ||
debounce?: boolean, | ||
events?: Record<string, Array<string>> | ||
modelTypes?: Record<string, object>, |
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.
This could probably be more specific than string
, to limit it to keyof Models
. Up to you if you think that's worth it though.
withRef?: boolean | ||
} | ||
|
||
export declare function connectBackboneToReact<Model extends {}, ModelProps extends {}>( |
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.
Naming nit: shouldn't this be Models
, not Model
? It's an object with multiple models in it, right?
} | ||
|
||
export declare function connectBackboneToReact<Model extends {}, ModelProps extends {}>( | ||
mapModelToProps: (models: Model, props: ModelProps) => Partial<ModelProps>, options?: Options |
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.
Another naming nit: it should be mapModelsToProps
export declare function connectBackboneToReact<Model extends {}, ModelProps extends {}>( | ||
mapModelToProps: (models: Model, props: ModelProps) => Partial<ModelProps>, options?: Options | ||
): <CombinedProps>( | ||
wrappedComponent: React.ComponentType<CombinedProps> | ||
) => React.ComponentType<Omit<CombinedProps, keyof ModelProps>>; |
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.
I think ModelProps
might be inconsistent here. As the second param to mapModelsToProps
, it should me all of the props passed in from the parent component. But then in the return type you're omitting those props from what needs to be passed in from the parent component.
Compared to what I had written in the JIRA ticket:
function connectBackboneToReact<Models extends {}, ModelProps extends {}>(
mapModelsToProps: (models: Models) => ModelProps
): <CombinedProps>(
WrappedComponent: React.ComponentType<CombinedProps>
) => React.ComponentType<Omit<CombinedProps, keyof ModelProps>>;
In that definition, ModelProps
was the props specifically being added by mapModelsToProps
, so omitting them from the generated component type meant that the parent wouldn't have to pass in anything that was derived from a backbone model. I didn't have a type included for the props
param though, so we probably can't just use that as-is. I'm not 100% sure what the best way to write that is where TS can still infer everything properly, tbh.
No description provided.