-
Notifications
You must be signed in to change notification settings - Fork 240
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
Consider including a TypeScript definition file #50
Comments
Good suggestion, I'd be happy to include a typescript definition file if someone wants to work on this and submit a PR. Unfortunately I don't think that I have time to currently work on adding typescript support. |
I am willing to help |
I've created a minimalist typescript definition file for redux-auth-wrapper ( very lightweight, but gets the job done ) I can add to the typings directory or add to this project as a pull request, do you have any preferences? index.d.ts import * as React from 'react';
declare var UserAuthWrapper: any;
declare interface UserAuthWrapper extends React.Component<any,any> {
children?: React.ReactElement<any>;
} -Patrick P.S. Thanks for creating this project, it's great! |
@gidich does this work for you? UserAuthWrapper is a higher order component that first takes the config object and then returns a component. Im not very familiar with the type script syntax but it looks to me like you are saying UserAuthWrapper is a component with this defenition |
@mjrussell this does indeed work for me, the approach I took was to add it to a separate type definition library. I'll try to see if it also works for me within the actual library. the following specifies that it is a higher order component:
which specifies that the following is legal:
|
Hmm but it is not being passed as children (because it is not rendered as a React Component in the Route definition, it is function being applied a component definition). I think it should look much more similar to the one from react-redux's connect. They behave very similarly to export function connect(mapStateToProps?: MapStateToProps,
mapDispatchToProps?: MapDispatchToPropsFunction|MapDispatchToPropsObject,
mergeProps?: MergeProps,
options?: Options): ClassDecorator;
interface MapStateToProps {
(state: any, ownProps?: any): any;
}
interface MapDispatchToPropsFunction {
(dispatch: Dispatch<any>, ownProps?: any): any;
}
interface MapDispatchToPropsObject {
[name: string]: ActionCreator<any>;
}
interface MergeProps {
(stateProps: any, dispatchProps: any, ownProps: any): any;
}
interface Options {
/**
* If true, implements shouldComponentUpdate and shallowly compares the result of mergeProps,
* preventing unnecessary updates, assuming that the component is a “pure” component
* and does not rely on any input or state other than its props and the selected Redux store’s state.
* Defaults to true.
* @default true
*/
pure: boolean;
} Except there would be only an config arg with all the properties described in the Readme's API. |
I have something like this in my project. I am not an expert 'typescripter' myself, so if you notice something that could be improved I would appreciate feedback, but for all of cases that I have encountered it works properly. declare module 'redux-auth-wrapper' {
import {Component, ComponentClass, StatelessComponent, ReactNode} from 'react';
interface UserAuthConfigObject {
authSelector: (state, ownProps?) => any;
authenticatingSelector?: (state, ownProps?) => Boolean;
LoadingComponent?: Component<any, any>;
FailureComponent?: Component<any, any>;
failureRedirectPath?: String | ((state, ownProps?) => String);
redirectQueryParamName?: String;
redirectAction?: Function;
wrapperDisplayName?: String;
predicate?: (authData: any) => Boolean;
allowRedirectBack?: Boolean | ((location, redirectPath) => Boolean);
propMapper?: Function;
}
interface UserAuthWrapperReturn {
onEnter: (state, nextState, replace) => any;
}
export type UserAuthWrapperDecorator = <TOriginalProps>(
component: ComponentClass<TOriginalProps> | StatelessComponent<TOriginalProps> | ReactNode
) => ComponentClass<TOriginalProps> & UserAuthWrapperReturn;
export function UserAuthWrapper(configObject: UserAuthConfigObject): UserAuthWrapperDecorator;
}
|
@klapek this looks great! I think it would be a great start for PR. I'd like to keep the |
If you want to take that on yourself that would be awesome, otherwise you can get the PR started and I can try to add some of the additional stuff to it |
Including typings directly in this repo would be great! There are some typings at DefinitelyTyped that could be useful as a starting point. |
@mjrussell Hey, any update on typings? |
@Kamahl19 have you tried using the ones from DefinitelyTyped? |
TypeScript is becoming more popular (angular 2 is written in TS and also some other "big boys" that I can't remember now too).
In case you're interested to add a d.ts definition file for this library you may want to start reading this and this.
The text was updated successfully, but these errors were encountered: