Skip to content

Commit c325495

Browse files
Merge pull request #38 from Mini-ghost/feature/multiple-endpoint-types
update v0.21.x type definition
2 parents 3e5fe41 + bb47d89 commit c325495

File tree

4 files changed

+63
-10
lines changed

4 files changed

+63
-10
lines changed

docs/content/en/index.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,47 @@ Or get `params` on `@beforeOpen` event:
586586

587587
<alert>`parmas` will be reset to `{}` automatically after `closed` event. You can avoid the modal to reset the `params` to empty object by calling `event.stop()`.</alert>
588588

589+
## TypeScript
590+
591+
### Vue
592+
Works out of the box in Vue, no other settings are required. But if you customized your access key, you must define the type yourself like below:
593+
594+
```ts
595+
import Vue from 'vue'
596+
import VueFinalModal, {
597+
VfmOptions,
598+
VueFinalModalProperty
599+
} from 'vue-final-modal'
600+
601+
Vue.use<VfmOptions>(VueFinalModal(), {
602+
componentName: 'MyComponentName',
603+
key: 'myKey',
604+
})
605+
606+
// define the type of access key yourself
607+
declare module 'vue/types/vue' {
608+
interface Vue {
609+
myKey: VueFinalModalProperty;
610+
}
611+
}
612+
```
613+
614+
### Nuxt
615+
616+
Add the types to your "types" array in tsconfig.json file
617+
618+
```js
619+
{
620+
"compilerOptions": {
621+
"types": [
622+
// other types
623+
// ...
624+
"vue-final-modal"
625+
]
626+
}
627+
}
628+
```
629+
589630
## **Contribution**
590631

591632
👋 Hi I'm Hunter, the author of `vue-final-modal`.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"files": [
1313
"lib",
1414
"dist",
15-
"types/index.d.ts",
15+
"types",
1616
"vetur"
1717
],
1818
"scripts": {

types/index.d.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Vue, { PluginObject } from 'vue'
2+
import './lib'
23

34
export class VueFinalModalComponant extends Vue {
45
$refs: {
@@ -7,17 +8,21 @@ export class VueFinalModalComponant extends Vue {
78
}
89
}
910

11+
export type VueFinalModalProperty = {
12+
readonly openedModals: VueFinalModalComponant[]
13+
readonly modals: VueFinalModalComponant[],
14+
get(name: string): VueFinalModalComponant | undefined
15+
show(name: string): void
16+
hide(name: string): void
17+
hideAll(): void
18+
toggle(name: string, params?: any): void
19+
toggle(name: string, show?: boolean, params?: any): void
20+
}
21+
22+
1023
declare module 'vue/types/vue' {
1124
interface Vue {
12-
readonly $vfm: {
13-
readonly openedModals: VueFinalModalComponant[]
14-
readonly modals: VueFinalModalComponant[]
15-
get(name: string): VueFinalModalComponant | undefined
16-
show(name: string): void
17-
hide(name: string): void
18-
hideAll(): void
19-
toggle(name: string, show: boolean): void
20-
}
25+
readonly $vfm: VueFinalModalProperty
2126
}
2227
}
2328

@@ -27,4 +32,5 @@ export interface VfmOptions {
2732
}
2833

2934
declare const VfmPlugin: () => PluginObject<VfmOptions>
35+
3036
export default VfmPlugin

types/lib.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare module 'vue-final-modal/lib' {
2+
import VfmPlugin from 'vue-final-modal'
3+
4+
export default VfmPlugin
5+
export * from 'vue-final-modal'
6+
}

0 commit comments

Comments
 (0)