- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.3k
 
Add typings #538
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
          
     Closed
      
      
    
  
     Closed
                    Add typings #538
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      68a4f2b
              
                Remove Style section
              
              
                timdorr 6a68d10
              
                add typings
              
              
                bbenezech 722e1b1
              
                add typings
              
              
                bbenezech ec99f1d
              
                first templates order and mapStateToProps
              
              
                bbenezech 52db71a
              
                fix template order and add second's API use case (no store subscription)
              
              
                bbenezech d8f4394
              
                remove unnecessary children prop and optional flag for store
              
              
                bbenezech 5793e0e
              
                add specific case for connect(null, mapDispatchToProps)
              
              
                bbenezech 2e444e8
              
                have StatelessComponent as the first type
              
              
                bbenezech 92326dd
              
                respect template parameters order in comments
              
              
                bbenezech 4f907f7
              
                fix template parameters order (oops, forgot that ones when copy-pasti…
              
              
                bbenezech 64b201e
              
                remove some dead code
              
              
                bbenezech 63655a9
              
                add TMergeProps generic
              
              
                bbenezech a6e0678
              
                mapState / mapDispatch can be factory functions (stolen from DT last …
              
              
                bbenezech 670c851
              
                make sure mapDispatchToProps returns TDispatchProps that is ALSO a ha…
              
              
                bbenezech d3519d4
              
                remove unused import
              
              
                bbenezech d3f6f24
              
                fix argument order for mergeProps (duh) and ComponentDecorator arguments
              
              
                bbenezech File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { ComponentClass, Component, StatelessComponent } from 'react'; | ||
| import { Store, Dispatch, ActionCreator } from 'redux'; | ||
| 
     | 
||
| interface ComponentDecorator<TOriginalProps, TOwnProps> { | ||
| (component: StatelessComponent<TOriginalProps>|ComponentClass<TOriginalProps>): ComponentClass<TOwnProps>; | ||
| } | ||
| 
     | 
||
| /** | ||
| * Following 5 functions cover all possible ways connect could be invoked | ||
| * | ||
| * - State: Redux state interface (the same one used by Store<S>) | ||
| * - TOwnProps: Props passed to the wrapping component | ||
| * - TStateProps: Result of MapStateToProps | ||
| * - TDispatchProps: Result of MapDispatchToProps | ||
| */ | ||
| function connect<State, TOwnProps>(): ComponentDecorator<{ dispatch: Dispatch<State> } & TOwnProps, TOwnProps>; | ||
| 
     | 
||
| function connect<State, TOwnProps, TStateProps>( | ||
| mapStateToProps: FuncOrSelf<MapStateToProps<State, TOwnProps, TStateProps>>, | ||
| ): ComponentDecorator<TStateProps & { dispatch: Dispatch<State> } & TOwnProps, TOwnProps>; | ||
| 
     | 
||
| function connect<State, TOwnProps, TStateProps, TDispatchProps>( | ||
| mapStateToProps: FuncOrSelf<MapStateToProps<State, TOwnProps, TStateProps>>, | ||
| mapDispatchToProps: FuncOrSelf<MapDispatchToPropsFunction<State, TOwnProps, TDispatchProps> | MapDispatchToPropsObject & TDispatchProps> | ||
| ): ComponentDecorator<TStateProps & TDispatchProps & TOwnProps, TOwnProps>; | ||
| 
     | 
||
| function connect<State, TOwnProps, TDispatchProps>( | ||
| mapStateToProps: null, | ||
| mapDispatchToProps: FuncOrSelf<MapDispatchToPropsFunction<State, TOwnProps, TDispatchProps> | MapDispatchToPropsObject & TDispatchProps> | ||
| ): ComponentDecorator<TDispatchProps & TOwnProps, TOwnProps>; | ||
| 
     | 
||
| function connect<State, TOwnProps, TStateProps, TDispatchProps, TMergeProps>( | ||
| mapStateToProps: FuncOrSelf<MapStateToProps<State, TOwnProps, TStateProps>>, | ||
| mapDispatchToProps: FuncOrSelf<MapDispatchToPropsFunction<State, TOwnProps, TDispatchProps>| MapDispatchToPropsObject & TDispatchProps>, | ||
| mergeProps: MergeProps<TOwnProps, TStateProps, TDispatchProps, TMergeProps>, | ||
| options?: Options | ||
| ): ComponentDecorator<TMergeProps, TOwnProps>; | ||
| 
     | 
||
| interface MapDispatchToPropsObject { | ||
| [name: string]: ActionCreator<any>; | ||
| } | ||
| 
     | 
||
| interface MapStateToProps<State, TOwnProps, TStateProps> { | ||
| (state: State, ownProps: TOwnProps): TStateProps; | ||
| } | ||
| 
     | 
||
| interface MapDispatchToPropsFunction<State, TOwnProps, TDispatchProps> { | ||
| (dispatch: Dispatch<State>, ownProps: TOwnProps): TDispatchProps; | ||
| } | ||
| 
     | 
||
| interface MergeProps<TOwnProps, TStateProps, TDispatchProps, TMergeProps> { | ||
| (stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps): TMergeProps; | ||
| } | ||
| 
     | 
||
| interface Options { | ||
| pure?: boolean; | ||
| withRef?: boolean; | ||
| } | ||
| 
     | 
||
| type FuncOrSelf<T> = T | (() => T); | ||
| 
     | 
||
| /** | ||
| * Typescript does not support generic components in tsx yet in an intuïtive way which is the reason we avoid a | ||
| * generic parameter in Store here by using any as the type | ||
| */ | ||
| export interface ProviderProps { | ||
| store: Store<any>; | ||
| } | ||
| 
     | 
||
| export class Provider extends Component<ProviderProps, {}> { } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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.
In a case of passing object to
mapDispatchToProps, what isTDispatchProps? What's the difference withMapDispatchToPropsObject?I think it should be a different signature for the case when
mapDispatchToPropsis object, something like this: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.
TDispatchPropsmay be set by the user. It's the list of dispatchable action creators he intends to use in the component.MapDispatchToPropsObjectis a constraint we add to make sure values of the hash are action creators.Adding a different signature is problematic because the combination will be very large. Same issue as with
mapStateToProps: null.