From 38f3da29967b0426b8a3f138cff69e7b9f1e69ad Mon Sep 17 00:00:00 2001 From: Fahmi Akbar Wildana Date: Wed, 14 Mar 2018 07:11:55 +0700 Subject: [PATCH 1/3] Add typescript support --- index.d.ts | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..6851d69 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,55 @@ +import Vue from 'vue' + +// Instance / File +global { + namespace VueUpload { + interface File { + readonly fileObject: boolean + id: string | number + size: number + name: string + type: string + active: boolean + error: string + success: boolean + putAction: string + postAction: string + headers: object + data: object + timeout: number + response: object | string + progress: string + speed: number + xhr: XMLHttpRequest + iframe: Element + } + } +} + +interface VueUploadComponent extends Vue, Element { + // Instance / Methods + get(id: VueUpload.File | object | string): VueUpload.File | object | boolean + add(files: Array | VueUpload.File | File | object): object | Array | boolean + addInputFile(el: HTMLInputElement): Array + addDataTransfer(dataTransfer: DataTransfer): Promise> + update(id: VueUpload.File | object | string, data: object): object | boolean + // remove(id: VueUpload.File | object | string): object | boolean // Types are incompatible with Element + replace(id1: VueUpload.File | object | string, id2: VueUpload.File | object | string): boolean + clear(): boolean + + // Instance / Data + readonly files: Array + readonly features: { html5?: boolean; directory?: boolean; drag?: boolean } + active: boolean + readonly dropActive: true + readonly uploaded: true +} + +// module 'vue/types/vue' { + // https://stackoverflow.com/a/41286276/5221998 + // interface Vue { + // readonly $refs: { [key: string]: VueUploadComponent }; + // } +// } + +export default VueUploadComponent From 631ad4b16b393979f4e85a6cc872a5079d84ce36 Mon Sep 17 00:00:00 2001 From: Fahmi Akbar Wildana Date: Wed, 14 Mar 2018 07:14:08 +0700 Subject: [PATCH 2/3] Make it import-able --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index be086cb..c3c2cf3 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "module": "dist/vue-upload-component.js", "unpkg": "dist/vue-upload-component.js", "jsdelivr": "dist/vue-upload-component.js", + "typings": "index.d.ts", "repository": { "type": "git", "url": "git+https://github.com/lian-yue/vue-upload-component.git" From 1ea52e241fb083292a0eeea10961db5defbe13ba Mon Sep 17 00:00:00 2001 From: Fahmi Akbar Wildana Date: Wed, 14 Mar 2018 07:33:25 +0700 Subject: [PATCH 3/3] Support `this.$refs.upload.___` using `as` --- index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 6851d69..4f3c22d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -26,14 +26,14 @@ global { } } -interface VueUploadComponent extends Vue, Element { +class _ extends Vue { // Instance / Methods get(id: VueUpload.File | object | string): VueUpload.File | object | boolean add(files: Array | VueUpload.File | File | object): object | Array | boolean addInputFile(el: HTMLInputElement): Array addDataTransfer(dataTransfer: DataTransfer): Promise> update(id: VueUpload.File | object | string, data: object): object | boolean - // remove(id: VueUpload.File | object | string): object | boolean // Types are incompatible with Element + remove(id: VueUpload.File | object | string): object | boolean replace(id1: VueUpload.File | object | string, id2: VueUpload.File | object | string): boolean clear(): boolean @@ -52,4 +52,4 @@ interface VueUploadComponent extends Vue, Element { // } // } -export default VueUploadComponent +export default _