Comments (12)
I am willing to help
from redux-auth-wrapper.
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;
}
from redux-auth-wrapper.
Including typings directly in this repo would be great! There are some typings at DefinitelyTyped that could be useful as a starting point.
from redux-auth-wrapper.
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.
from redux-auth-wrapper.
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!
from redux-auth-wrapper.
@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
from redux-auth-wrapper.
@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:
children?: React.ReactElement<any>;
which specifies that the following is legal:
<Route path="foo" component={UserIsAuthenticated(Foo)}/>
from redux-auth-wrapper.
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
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/react-redux/react-redux-2.1.2.d.ts:
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.
from redux-auth-wrapper.
@klapek this looks great! I think it would be a great start for PR.
I'd like to keep the d.ts
file co-located with the project, and probably add some tests, similar to what Definitively typed does - https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/react-redux
from redux-auth-wrapper.
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
from redux-auth-wrapper.
@mjrussell Hey, any update on typings?
from redux-auth-wrapper.
@Kamahl19 have you tried using the ones from DefinitelyTyped?
from redux-auth-wrapper.
Related Issues (20)
- [Possible Bug] Async Validation in a multi-step form HOT 1
- How to make chunk js with react-router HOT 1
- Error in UserAuthWrapper
- Hande logout when expired token in axios interceptors but not redirect to login page HOT 2
- Misleading naming of authenticatedSelector HOT 2
- Example with react 16.x HOT 1
- Reducer not yet defined HOT 2
- Usage with react-cookies
- not running when am trying do npm start HOT 1
- connectedReduxRedirect is missing HOT 1
- Deprecated lifecycle method in redirect.js HOT 7
- Doesn't work with latest react HOT 3
- Type {} is missing the following properties from type Readonly<InjectedAuthProps> HOT 1
- ES6 Module - Error when using with Electron HOT 2
- redirect.js replace UNSAFE_componentWillMount with componentDidMount HOT 6
- No question mark befor query param on redirect HOT 2
- Versioning Order HOT 4
- React-router v6 HOT 9
- Infinite loop (redirect ) with nesting wrappers HOT 1
- Call for mantainers! HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-auth-wrapper.