Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix up typing issues
  • Loading branch information
timpur committed Jun 7, 2018
commit b26a73efd47a4c4e9a22fade45a7859bcbbec44a
4 changes: 4 additions & 0 deletions devtools.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "unistore/devtools" {
import { Store } from "unistore";
export default function devtools<TStoreState>(store: Store<TStoreState>): Store<TStoreState>;
}
2 changes: 1 addition & 1 deletion devtools.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function unistoreDevTools(store) {
module.exports.default = function unistoreDevTools(store) {
var extension = window.__REDUX_DEVTOOLS_EXTENSION__ || window.top.__REDUX_DEVTOOLS_EXTENSION__;
var ignoreState = false;

Expand Down
49 changes: 27 additions & 22 deletions preact.d.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
declare module "unistore/preact" {
import * as Preact from "preact";
import { Store, ActionAny } from "unistore";
import { Store, Action, ActionAny } from "unistore";

// Diff / Omit taken from https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-311923766
type Diff<T extends string, U extends string> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;

export interface ProviderProps<TStoreState> {
store: Store<TStoreState>;
store: Store<TStoreState>;
}
export class Provider<IProps extends ProviderProps<TStoreState>, TStoreState> extends Preact.Component<IProps, {}> {
render(props: any, state: any): JSX.Element;
render(props: any, state: any): JSX.Element;
}

//Props

interface MapStateToProps<TStoreState, TExternalProps, TStoreProps> {
(state: TStoreState, ownProps: TExternalProps): TStoreProps;
(state: TStoreState, ownProps: TExternalProps): TStoreProps;
}
type MapStateToPropsParam<TStoreState, TExternalProps, TStoreProps> = MapStateToProps<TStoreState, TExternalProps, TStoreProps> | null | undefined;

interface MapActionsToPropsFunction<TStoreState> {
[actionName: string]: ActionAny<TStoreState> | ActionAny<TStoreState>;
[actionName: string]: Action<TStoreState> | ActionAny<TStoreState>;
}
interface MapActionsToPropsFactory<TStoreState, TActionProps> {
<TActionProps>(store: Store<TStoreState>): TActionProps;
(store: Store<TStoreState>): TActionProps;
}
type MapActionsToPropsParam<TActionProps, TStoreState> = MapActionsToPropsFactory<TStoreState, TActionProps>; //| MapActionsToPropsFunction<TStoreState>;
type MapActionsToPropsParam<TStoreState, TActionProps> = MapActionsToPropsFactory<TStoreState, TActionProps>;

type DefaultMapActionToProps<TStoreState> = { store: Store<TStoreState> }

Expand All @@ -35,31 +35,36 @@ declare module "unistore/preact" {
type AnyComponent<PropsType, StateType> = FunctionalComponent<PropsType> | Component<PropsType, StateType>;

interface InferableComponentEnhancerWithProps<TInjectedProps, TNeedProps> {
<TProps extends TInjectedProps, TState = {}>(
component: AnyComponent<TProps, TState>
): Preact.FunctionalComponent<Omit<TProps, keyof TInjectedProps> & TNeedProps> & { WrappedComponent: Preact.FunctionalComponent<TProps> }
<TProps extends TInjectedProps, TState = {}>(
component: AnyComponent<TProps, TState>
): Preact.FunctionalComponent<Omit<TProps, keyof TInjectedProps> & TNeedProps> & { WrappedComponent: Preact.FunctionalComponent<TProps> }
}

type InferableComponentEnhancer<TInjectedProps> = InferableComponentEnhancerWithProps<TInjectedProps, {}>


export interface Connect {
(): InferableComponentEnhancer<DefaultMapActionToProps<any>>;
(): InferableComponentEnhancer<DefaultMapActionToProps<any>>;

<TStoreProps={}, TExternalProps={}, TStoreState={}>(
mapStateToProps: MapStateToPropsParam<TStoreState, TExternalProps, TStoreProps>
): InferableComponentEnhancerWithProps<TStoreProps & DefaultMapActionToProps<TStoreState>, TExternalProps>;
<TStoreProps={}, TExternalProps={}, TStoreState={}>(
mapStateToProps: MapStateToPropsParam<TStoreState, TExternalProps, TStoreProps>
): InferableComponentEnhancerWithProps<TStoreProps & DefaultMapActionToProps<TStoreState>, TExternalProps>;

<T extends string, TStoreProps={ [K in T]: any }, TExternalProps={}>(
mapStateToProps: T[]
): InferableComponentEnhancerWithProps<TStoreProps & DefaultMapActionToProps<any>, TExternalProps>;
<T extends string, TStoreProps={ [K in T]: any }, TExternalProps={}>(
mapStateToProps: T[]
): InferableComponentEnhancerWithProps<TStoreProps & DefaultMapActionToProps<any>, TExternalProps>;

<TStoreProps={}, TActionProps extends MapActionsToPropsFunction<TStoreState>={}, TActionPropsRemap = { [K in keyof TActionProps]: (...args) => void }, TExternalProps={}, TStoreState={}>(
mapStateToProps: MapStateToPropsParam<TStoreState, TExternalProps, TStoreProps>,
mapActionsToProps: MapActionsToPropsParam<TActionProps, TStoreState>
): InferableComponentEnhancerWithProps<TStoreProps & TActionPropsRemap, TExternalProps>;
<TStoreProps={}, TActionProps extends MapActionsToPropsFunction<TStoreState>={}, TActionPropsRemap = { [K in keyof TActionProps]: (...args) => void }, TExternalProps={}, TStoreState={}>(
mapStateToProps: MapStateToPropsParam<TStoreState, TExternalProps, TStoreProps>,
mapActionsToProps: MapActionsToPropsParam<TStoreState, TActionProps> | TActionProps
): InferableComponentEnhancerWithProps<TStoreProps & TActionPropsRemap, TExternalProps>;

<T extends string, TStoreProps={ [K in T]: any }, TActionProps extends MapActionsToPropsFunction<TStoreState>={}, TActionPropsRemap = { [K in keyof TActionProps]: (...args) => void }, TExternalProps={}, TStoreState={}>(
mapStateToProps: T[],
mapActionsToProps: MapActionsToPropsParam<TStoreState, TActionProps> | TActionProps
): InferableComponentEnhancerWithProps<TStoreProps & TActionPropsRemap, TExternalProps>;

}

export const connect: Connect;
}
}