diff --git a/docs/faq.md b/docs/faq.md new file mode 100644 index 0000000..e72c8cb --- /dev/null +++ b/docs/faq.md @@ -0,0 +1,21 @@ +## 在 TypeScript 中指定组件的类型 + +```html + + +``` diff --git a/package.json b/package.json index c10ffd7..c9ac7b2 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "browser": { "./sfc": "src/upload-to-ali.vue" }, + "types": "src/upload-to-ali.d.ts", "scripts": { "dev": "vue-styleguidist server", "test": "jest", diff --git a/src/upload-to-ali.d.ts b/src/upload-to-ali.d.ts new file mode 100644 index 0000000..c049df7 --- /dev/null +++ b/src/upload-to-ali.d.ts @@ -0,0 +1,90 @@ +import Vue, {VueConstructor} from 'vue' + +declare module '@femessage/upload-to-ali' { + class FemessageComponent extends Vue { + static install(vue: typeof Vue): void + } + + type CombinedVueInstance< + Instance extends Vue, + Data, + Methods, + Computed, + Props + > = Data & Methods & Computed & Props & Instance + + type ExtendedVue< + Instance extends Vue, + Data, + Methods, + Computed, + Props + > = VueConstructor< + CombinedVueInstance & Vue + > + + type Combined = Data & + Methods & + Computed & + Props + + type UploadToAliData = { + previewUrl: string + + uploading: boolean + + isHighlight: boolean + } + + type UploadToAliMethods = { + selectFiles: () => void + } + + type UploadToAliComputed = { + uploadList: any[] + canUpload: boolean + uploadRequest: (file: any) => Promise + } + + type UploadToAliProps = { + action: string + bucket: string + region: string + dir: string + customDomain: string + value: string | any[] + multiple: boolean + size: number + accept: string + timeout: number + disabled: boolean + max: number + compressOptions: {[key: string]: any} + uploadOptions: {[key: string]: any} + preview: boolean + tip: string + onClick: (url: string, isFile: boolean) => void + beforeUpload: (files: any[]) => Promise + onOversize: (fileOvesize: any) => void + request: (file: any) => Promise + } + + type UploadToAli = Combined< + UploadToAliData, + UploadToAliMethods, + UploadToAliComputed, + UploadToAliProps + > + + export interface UploadToAliType extends FemessageComponent, UploadToAli {} + + const UploadToAliConstruction: ExtendedVue< + Vue, + UploadToAliData, + UploadToAliMethods, + UploadToAliComputed, + UploadToAliProps + > + + export default UploadToAliConstruction +}