From 0a81e8c69d9040abd69d186fb9e2bd4f2df142b0 Mon Sep 17 00:00:00 2001 From: xcatliu Date: Mon, 26 Nov 2018 11:22:42 +0800 Subject: [PATCH 1/2] Add observe type for typescript --- packages/omi/src/omi.d.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/omi/src/omi.d.ts b/packages/omi/src/omi.d.ts index 68528e986..cd068dce9 100644 --- a/packages/omi/src/omi.d.ts +++ b/packages/omi/src/omi.d.ts @@ -2,6 +2,7 @@ export = Omi; export as namespace Omi; declare namespace Omi { + type Callback = (...args: any[]) => void; type Key = string | number; type Ref = (instance: T) => void; type ComponentChild = VNode | object | string | number | boolean | null; @@ -109,6 +110,12 @@ declare namespace Omi { abstract render(props: RenderableProps

, data: D): void; } + // The class type (not instance of class) + // https://stackoverflow.com/q/42753968/2777142 + type WeElementConstructor = { + new(): WeElement; + } + abstract class ModelView

{ constructor(); @@ -164,10 +171,11 @@ declare namespace Omi { function render(vnode: ComponentChild, parent: string | Element | Document | ShadowRoot | DocumentFragment, store?: object): void; - function define(name: string, ctor: any): void; - function tag(name: string, pure?: boolean): (ctor: any) => void; - function tick(callback: () => void, scope?: any): void; - function nextTick(callback: () => void, scope?: any): void; + function define(name: string, ctor: WeElementConstructor): void; + function tag(name: string, pure?: boolean): (ctor: WeElementConstructor) => void; + function tick(callback: Callback, scope?: any): void; + function nextTick(callback: Callback, scope?: any): void; + function observe(target: WeElementConstructor): void; var options: { vnode?: (vnode: VNode) => void; From f745a786a98e9b9a3606c138a88273fb1c63bddd Mon Sep 17 00:00:00 2001 From: xcatliu Date: Mon, 26 Nov 2018 11:24:05 +0800 Subject: [PATCH 2/2] Update type to interface --- packages/omi/src/omi.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/omi/src/omi.d.ts b/packages/omi/src/omi.d.ts index cd068dce9..cd563de51 100644 --- a/packages/omi/src/omi.d.ts +++ b/packages/omi/src/omi.d.ts @@ -112,7 +112,7 @@ declare namespace Omi { // The class type (not instance of class) // https://stackoverflow.com/q/42753968/2777142 - type WeElementConstructor = { + interface WeElementConstructor { new(): WeElement; }