diff --git a/docs/faq.md b/docs/faq.md new file mode 100644 index 0000000..eff0f78 --- /dev/null +++ b/docs/faq.md @@ -0,0 +1,13 @@ +## 在 TypeScript 中指定组件的类型 + +```html + +``` \ No newline at end of file diff --git a/package.json b/package.json index f81dfa8..717643a 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "browser": { "./sfc": "src/v-editor.vue" }, + "types": "src/v-editor.d.ts", "scripts": { "dev": "vue-styleguidist server", "test": "jest --verbose", diff --git a/src/v-editor.d.ts b/src/v-editor.d.ts new file mode 100644 index 0000000..0645834 --- /dev/null +++ b/src/v-editor.d.ts @@ -0,0 +1,72 @@ +import Vue, {VueConstructor} from 'vue' + +declare module '@femessage/v-editor' { + 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 VEditorData = { + editor: any + ClassicEditor: any + isFullScreen: boolean + uploaderAccept: string + previewImageUrl: string + } + + type VEditorMethods = {} + + type VEditorComputed = {} + + type VEditorProps = { + placeholder: string + height: number | string + uploadOptions: object + value: string + editorOptions: object + disabled: boolean + onUploadFail: (status: boolean, error?: any) => void + autosize: object + } + + type VEditor = Combined< + VEditorData, + VEditorMethods, + VEditorComputed, + VEditorProps + > + + export interface VEditorType extends FemessageComponent, VEditor {} + + const VEditorConstruction: ExtendedVue< + Vue, + VEditorData, + VEditorMethods, + VEditorComputed, + VEditorProps + > + + export default VEditorConstruction +} diff --git a/styleguide.config.js b/styleguide.config.js index 0c97462..c5dc214 100644 --- a/styleguide.config.js +++ b/styleguide.config.js @@ -39,6 +39,10 @@ module.exports = { name: 'Demo', sections: demoSections, sectionDepth: 2 + }, + { + name: 'FAQ', + content: 'docs/faq.md' } ], webpackConfig: {