Skip to content

Commit

Permalink
feat: add types (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
gd4Ark authored Nov 11, 2020
1 parent 6b96ac9 commit 183e4e9
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## 在 TypeScript 中指定组件的类型

```html
<script lang="ts">
// 需要引入这个
// import { VEditorType } from '@femessage/v-editor'
export default {
mounted() {
(this.$refs.editor as VEditorType).height = 120
},
}
</script>
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"browser": {
"./sfc": "src/v-editor.vue"
},
"types": "src/v-editor.d.ts",
"scripts": {
"dev": "vue-styleguidist server",
"test": "jest --verbose",
Expand Down
72 changes: 72 additions & 0 deletions src/v-editor.d.ts
Original file line number Diff line number Diff line change
@@ -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<Instance, Data, Methods, Computed, Props> & Vue
>

type Combined<Data, Methods, Computed, Props> = 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
}
4 changes: 4 additions & 0 deletions styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ module.exports = {
name: 'Demo',
sections: demoSections,
sectionDepth: 2
},
{
name: 'FAQ',
content: 'docs/faq.md'
}
],
webpackConfig: {
Expand Down

0 comments on commit 183e4e9

Please sign in to comment.