From b8dd6a05f49b26b4e8f77a9678c3030ca527a706 Mon Sep 17 00:00:00 2001 From: Jiayu Liu Date: Mon, 25 Jun 2018 08:44:32 +0800 Subject: [PATCH 1/2] add wepy-redux --- types/wepy-redux/index.d.ts | 21 ++++++++++++++++++++ types/wepy-redux/tsconfig.json | 17 ++++++++++++++++ types/wepy-redux/tslint.json | 3 +++ types/wepy-redux/wepy-redux-tests.ts | 29 ++++++++++++++++++++++++++++ types/wepy/index.d.ts | 18 ++++++++++++----- 5 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 types/wepy-redux/index.d.ts create mode 100644 types/wepy-redux/tsconfig.json create mode 100644 types/wepy-redux/tslint.json create mode 100644 types/wepy-redux/wepy-redux-tests.ts diff --git a/types/wepy-redux/index.d.ts b/types/wepy-redux/index.d.ts new file mode 100644 index 0000000000..8cf026382d --- /dev/null +++ b/types/wepy-redux/index.d.ts @@ -0,0 +1,21 @@ +// Type definitions for wepy-redux 1.7 +// Project: https://github.com/Tencent/wepy/tree/1.7.x/packages/wepy-redux +// Definitions by: Jiayu Liu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import wepy from "wepy"; + +export interface MapStateToProps { + [propName: string]: ((state: any) => any) | string; +} +export interface MapDispatchToProps { + [propName: string]: ((store: any, ...args: any[]) => void) | string; +} + +export function connect( + mapStateToProps: MapStateToProps, + mapDispatchToProps: MapDispatchToProps +): (original: wepy.component) => wepy.component; + +export function setStore(store: any): void; diff --git a/types/wepy-redux/tsconfig.json b/types/wepy-redux/tsconfig.json new file mode 100644 index 0000000000..c7cc00bebf --- /dev/null +++ b/types/wepy-redux/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "experimentalDecorators": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "wepy-redux-tests.ts"] +} diff --git a/types/wepy-redux/tslint.json b/types/wepy-redux/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/wepy-redux/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/wepy-redux/wepy-redux-tests.ts b/types/wepy-redux/wepy-redux-tests.ts new file mode 100644 index 0000000000..ab6dbf138b --- /dev/null +++ b/types/wepy-redux/wepy-redux-tests.ts @@ -0,0 +1,29 @@ +import wepy from "wepy"; +import { connect } from "wepy-redux"; + +interface State { + counter: { + num: number; + }; +} + +@connect( + { + num(state: State) { + return state.counter.num; + }, + inc: "inc" + }, + { + addNum: "INCREMENT", + asyncInc: () => {} + } +) +export default class Index extends wepy.page { + // ... + methods = { + // ... + }; + // ... + onLoad() {} +} diff --git a/types/wepy/index.d.ts b/types/wepy/index.d.ts index bff673ee8c..e15de0964a 100644 --- a/types/wepy/index.d.ts +++ b/types/wepy/index.d.ts @@ -13,12 +13,20 @@ import util from "./util"; import base from "./base"; import { WxEnhances } from "./wx_enhanced"; +export as namespace wepy; + +export type event = typeof event; +export type component = typeof component; +export type app = typeof app; +export type page = typeof page; +export type mixin = typeof mixin; + interface DefaultExport extends WxEnhances { - event: typeof event; - app: typeof app; - component: typeof component; - page: typeof page; - mixin: typeof mixin; + event: wepy.event; + app: wepy.app; + component: wepy.component; + page: wepy.page; + mixin: wepy.mixin; $createApp: typeof base.$createApp; $createPage: typeof base.$createPage; $isEmpty: typeof util.$isEmpty; From 4d7932fa69c039f51960afac7dd48b65ac9724dc Mon Sep 17 00:00:00 2001 From: Jiayu Liu Date: Tue, 26 Jun 2018 23:51:21 +0800 Subject: [PATCH 2/2] update generics --- types/wepy-redux/index.d.ts | 2 +- types/wepy-redux/wepy-redux-tests.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/types/wepy-redux/index.d.ts b/types/wepy-redux/index.d.ts index 8cf026382d..8e16e57b27 100644 --- a/types/wepy-redux/index.d.ts +++ b/types/wepy-redux/index.d.ts @@ -16,6 +16,6 @@ export interface MapDispatchToProps { export function connect( mapStateToProps: MapStateToProps, mapDispatchToProps: MapDispatchToProps -): (original: wepy.component) => wepy.component; +): ((original: T) => T); export function setStore(store: any): void; diff --git a/types/wepy-redux/wepy-redux-tests.ts b/types/wepy-redux/wepy-redux-tests.ts index ab6dbf138b..65274613ab 100644 --- a/types/wepy-redux/wepy-redux-tests.ts +++ b/types/wepy-redux/wepy-redux-tests.ts @@ -20,10 +20,10 @@ interface State { } ) export default class Index extends wepy.page { - // ... + // methods methods = { - // ... + // method values }; - // ... + // on load onLoad() {} }