diff --git a/types/mirrorx/index.d.ts b/types/mirrorx/index.d.ts new file mode 100644 index 0000000000..66f85e14e7 --- /dev/null +++ b/types/mirrorx/index.d.ts @@ -0,0 +1,183 @@ +// Type definitions for mirrorx 0.2 +// Project: https://github.com/mirrorjs/mirror +// Definitions by: Aaronphy +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +import * as H from 'history'; + +import * as React from 'react'; + +import { Connect } from 'react-redux'; +import { match } from "react-router"; + +export type Diff = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]; +export type Omit = Pick>; + +export interface model { + name: string; + initialState?: any; + reducers?: any; + effects?: any; +} + +export interface _model { + name: string; + reducers: any; +} +export interface LinkProps extends React.AnchorHTMLAttributes { + to: H.LocationDescriptor; + replace?: boolean; +} +export interface NavLinkProps extends LinkProps { + activeClassName?: string; + activeStyle?: React.CSSProperties; + exact?: boolean; + strict?: boolean; + isActive?(match: match, location: H.Location): boolean; + location?: H.Location; +} + +export interface SwitchProps { + children?: React.ReactNode; + location?: H.Location; +} + +export interface RedirectProps { + to: H.LocationDescriptor; + push?: boolean; + from?: string; + path?: string; + exact?: boolean; + strict?: boolean; +} + +export interface RouteComponentProps

{ + match: match

; + location: H.Location; + history: H.History; + staticContext?: any; +} + +export interface RouteProps { + location?: H.Location; + component?: React.ComponentType> | React.ComponentType; + render?: ((props: RouteComponentProps) => React.ReactNode); + children?: ((props: RouteComponentProps) => React.ReactNode) | React.ReactNode; + path?: string; + exact?: boolean; + strict?: boolean; +} + +export interface PromptProps { + message: string | ((location: H.Location) => string | boolean); + when?: boolean; +} + +export interface LocationActionPayload { + method: string; + args?: any[]; +} + +export interface RouterAction { + type: '@@router/CALL_HISTORY_METHOD'; + payload: LocationActionPayload; +} + +export interface routeActions { + push(location: any, state?: any): RouterAction; + replace(location: any, state?: any): RouterAction; + go(n: number): RouterAction; + goBack(): RouterAction; + goForward(): RouterAction; +} + +export interface ConnectedRouterProps { + store?: any; + history?: H.History; +} + +export interface Actions { + routing: routeActions; + [propName: string]: any; +} + +export interface defaultOptions { + initialState?: {}; + historyMode?: string; + middlewares: any[]; + reducers: {}; + addEffect(name: string, handler: () => any): any; +} + +export interface Renderer { + ( + element: React.DOMElement, T>, + container: Element | null, + callback?: () => void + ): T; + + ( + element: Array, any>>, + container: Element | null, + callback?: () => void + ): Element; + + ( + element: React.SFCElement | Array>, + container: Element | null, + callback?: () => void + ): void; + + >( + element: React.CElement, + container: Element | null, + callback?: () => void + ): T; + + ( + element: Array>>, + container: Element | null, + callback?: () => void + ): React.Component; + +

( + element: React.ReactElement

, + container: Element | null, + callback?: () => void + ): React.Component | Element | void; + + ( + element: Array>, + container: Element | null, + callback?: () => void + ): React.Component | Element | void; + + ( + parentComponent: React.Component | Array>, + element: React.SFCElement, + container: Element, + callback?: () => void + ): void; +} + +/** + * This method is used to create and inject a model. + */ +export function model(options: model): _model; +/** + * connect connects your React component to your Redux store + */ +export const connect: Connect; +export const actions: Actions; +export function hook(): (subscriber: () => any) => any; +export function defaults(): (options: defaultOptions) => void; +export const render: Renderer; +export class Router extends React.Component> { } +export class Link extends React.Component { } +export class NavLink extends React.Component { } +export class Redirect extends React.Component { } +export class Route extends React.Component { } +export class Prompt extends React.Component { } +export function withRouter

>(component: React.ComponentType

): React.ComponentClass>>; +export function withRouter>(target: TFunction): TFunction; diff --git a/types/mirrorx/mirrorx-tests.ts b/types/mirrorx/mirrorx-tests.ts new file mode 100644 index 0000000000..c608828e14 --- /dev/null +++ b/types/mirrorx/mirrorx-tests.ts @@ -0,0 +1,24 @@ +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; +import mirror = require('mirrorx'); +/** + * add mirror.model.tests + */ +mirror.model({ + name: 'app', + initialState: 0, + reducers: { + increment(state: any) { return state + 1; }, + decrement(state: any) { return state - 1; } + }, + effects: { + async incrementAsync() { + await new Promise((resolve, reject) => { + setTimeout(() => { + resolve(); + }, 1000); + }); + mirror.actions.app.increment(); + } + } +}); diff --git a/types/mirrorx/tsconfig.json b/types/mirrorx/tsconfig.json new file mode 100644 index 0000000000..561f5cdab4 --- /dev/null +++ b/types/mirrorx/tsconfig.json @@ -0,0 +1,26 @@ +{ + "files": [ + "index.d.ts", + "mirrorx-tests.ts" + ], + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "jsx": "react", + "experimentalDecorators": true, + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + } +} \ No newline at end of file diff --git a/types/mirrorx/tslint.json b/types/mirrorx/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/mirrorx/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file