Coder Social home page Coder Social logo

Comments (12)

goemen avatar goemen commented on September 15, 2024 3

I am willing to help

from redux-auth-wrapper.

jaszczw avatar jaszczw commented on September 15, 2024 3

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.

jonaskello avatar jonaskello commented on September 15, 2024 2

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.

mjrussell avatar mjrussell commented on September 15, 2024

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.

gidich avatar gidich commented on September 15, 2024

@mjrussell

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.

mjrussell avatar mjrussell commented on September 15, 2024

@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.

gidich avatar gidich commented on September 15, 2024

@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.

mjrussell avatar mjrussell commented on September 15, 2024

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.

mjrussell avatar mjrussell commented on September 15, 2024

@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.

mjrussell avatar mjrussell commented on September 15, 2024

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.

Kamahl19 avatar Kamahl19 commented on September 15, 2024

@mjrussell Hey, any update on typings?

from redux-auth-wrapper.

mjrussell avatar mjrussell commented on September 15, 2024

@Kamahl19 have you tried using the ones from DefinitelyTyped?

from redux-auth-wrapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.