From 0533d5990abc7bf189d84fd5c219fb08bc02e45f Mon Sep 17 00:00:00 2001 From: hhh <1340545944@qq.com> Date: Thu, 24 Jan 2019 20:20:28 +0800 Subject: [PATCH] fix type declarations --- src/core/HNode.ts | 28 ++++++++++++---------------- src/core/HUI.ts | 6 +++--- src/core/registry.ts | 7 +++---- test/src/Timer.tsx | 8 ++------ 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/core/HNode.ts b/src/core/HNode.ts index 1dd8df4..1e30cc2 100644 --- a/src/core/HNode.ts +++ b/src/core/HNode.ts @@ -9,8 +9,8 @@ import { EventMap } from "./events"; type ArrayWrapped = T extends any[] ? T : [T]; -export type HProps

= {}> = { - [K in keyof P]-?: K extends 'children' ? ( +export type HProps

= { + [K in keyof P]: K extends 'children' ? ( P extends { children: any } ? ( ArrayWrapped ) : ( @@ -21,33 +21,29 @@ export type HProps

= {}> = { ) ) ) : ( - K extends keyof DP ? ( - Exclude - ) : ( - P[K] | undefined - ) + P[K] | undefined ); } & ('children' extends keyof P ? {} : { children: unknown[]; }); -export interface HDesc

= any, CH extends HandlerMap = any, DP extends Partial

= {}> { - defaultProps?: DP; +export interface HDesc

= any, CH extends HandlerMap = any> { + defaultProps?: Partial

; defaultStore?: Partial; storeHandlers?: PartialHandlers>; state?: Array; context?: Array; - init?: (this: HNode, props: HProps, store: Store, context: Store) => void; - render: (this: HNode, props: HProps, store: Store, context: Store) => unknown; - clear?: (this: HNode, props: HProps, store: Store, context: Store) => void; - catch?: (this: HNode, err: any, props: HProps, store: Store, context: Store) => unknown; + init?: (this: HNode, props: HProps

, store: Store, context: Store) => void; + render: (this: HNode, props: HProps

, store: Store, context: Store) => unknown; + clear?: (this: HNode, props: HProps

, store: Store, context: Store) => void; + catch?: (this: HNode, err: any, props: HProps

, store: Store, context: Store) => unknown; } -export interface HNode

= any, CH extends HandlerMap = any, DP extends Partial

= {}> { +export interface HNode

= any, CH extends HandlerMap = any> { isHN: true; type: unknown; - desc?: HDesc; - props: HProps; + desc?: HDesc; + props: HProps

; sto?: Store; ctx?: Store; owner?: HNode; diff --git a/src/core/HUI.ts b/src/core/HUI.ts index 72d16d4..4252de3 100644 --- a/src/core/HUI.ts +++ b/src/core/HUI.ts @@ -10,13 +10,13 @@ import { compare } from "../utils/cmp"; import { Fragment } from "../ext/Fragment"; import { noCmpProps } from "../ticker/patch"; -export const HUI =

= any, CH extends HandlerMap = any, DP extends Partial

= {}>( +export const HUI =

= any, CH extends HandlerMap = any>( type: HType | string, props?: P | null, ...children: unknown[] -): HNode => ({ +): HNode => ({ isHN: true, type, desc: registry.get(type), - props: _assign({ children: children.flat(_Infinity) }, props) as unknown as HProps, + props: _assign({ children: children.flat(_Infinity) }, props) as unknown as HProps

, active: true }); diff --git a/src/core/registry.ts b/src/core/registry.ts index f225d6b..49aec67 100644 --- a/src/core/registry.ts +++ b/src/core/registry.ts @@ -6,16 +6,15 @@ export interface HType

, context: Store): any; }; -export const registry = new _Map | string, HDesc>(); +export const registry = new _Map | string, HDesc>(); export const define = function < P extends object = any, S extends object = any, C extends object = any, SH extends HandlerMap = any, - CH extends HandlerMap = any, - DP extends Partial

= {} ->(name: string, desc: HDesc): HType { + CH extends HandlerMap = any +>(name: string, desc: HDesc): HType { const type = _Symbol(name) as unknown as HType; diff --git a/test/src/Timer.tsx b/test/src/Timer.tsx index b8bf185..d417ac5 100644 --- a/test/src/Timer.tsx +++ b/test/src/Timer.tsx @@ -11,11 +11,7 @@ type TimerStoreHandlers = { setInterval: (interval: number) => any; } -interface TimerDefaultProps { - start: number; -} - -const Timer = HUI.define('Timer', { +const Timer = HUI.define('Timer', { state: ['time'], @@ -32,7 +28,7 @@ const Timer = HUI.define