From 916d467ab6b624856249ed62335f249f579e2a96 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 18 Sep 2018 17:22:49 +0800 Subject: [PATCH] [type] add type definition (#590) --- tsconfig.json | 7 ++++++- types/index.d.ts | 23 +++++++++++++++++++++++ types/weapp.d.ts | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 types/index.d.ts create mode 100644 types/weapp.d.ts diff --git a/tsconfig.json b/tsconfig.json index 4a5ece01..8402fd67 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,13 @@ { "compilerOptions": { + "baseUrl": ".", "module": "commonjs", "removeComments": true, + "noImplicitThis": true, "noImplicitUseStrict": true }, - "files": ["packages/**/*"] + "include": [ + "types/**/*", + "packages/**/*" + ] } diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 00000000..7bc223dd --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,23 @@ +type Mixins = any[]; +type Relations = object; +type ExternalClasses = string[]; + +export interface Vue { + $emit(name: string, detail?: any): void; +} + +export type VantComponentOptions = { + data?: Data; + props?: Props; + field?: boolean; + mixins?: Mixins; + relations?: Relations; + classes?: ExternalClasses; + methods?: Methods & ThisType; + + // lifetimes + beforeCreate?: () => void; + created?: () => void; + mounted?: () => void; + destroyed?: () => void; +} diff --git a/types/weapp.d.ts b/types/weapp.d.ts new file mode 100644 index 00000000..92c675b8 --- /dev/null +++ b/types/weapp.d.ts @@ -0,0 +1,38 @@ +declare function Component(options: any): void; + +declare namespace Weapp { + interface Component { + getRelationNodes(selector: string): any[]; + setData(data: any, callback?: Function): void; + } + + interface Target { + id: string; + tagName: string; + dataset: any; + } + + interface Event { + type: string; + timeStamp: number; + target: Target; + currentTarget: Target; + } + + interface Touch { + identifier: number; + pageX: number; + pageY: number; + clientX: number; + clientY: number; + } + + interface TouchEvent extends Event { + touches: Array; + changedTouches: Array; + } + + interface CustomEvent extends Event { + detail: any; + } +}