Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add types #126

Merged
merged 1 commit into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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