Browse Source

🎈 perf(type): 修改指令类型展示

陈雪 1 month ago
parent
commit
89d5a32429
4 changed files with 9 additions and 11 deletions
  1. 1 1
      src/directives/format.ts
  2. 0 2
      src/directives/index.ts
  3. 0 8
      src/env.d.ts
  4. 8 0
      src/typings.d.ts

+ 1 - 1
src/directives/format.ts

@@ -1,6 +1,6 @@
 import { Directive, DirectiveBinding } from 'vue'
 
-type FormatType = 'date' | 'number'
+export type FormatType = 'date' | 'number'
 
 export const vFormat: Directive = {
   mounted(el: HTMLElement, { value }: DirectiveBinding<FormatType>) {

+ 0 - 2
src/directives/index.ts

@@ -1,8 +1,6 @@
 import { App } from 'vue'
 import { vFormat } from './format'
 
-export type FormatType = 'date' | 'number'
-
 export default function Directives(app: App) {
   app.directive('format', vFormat)
 }

+ 0 - 8
src/env.d.ts

@@ -1,7 +1,5 @@
 /// <reference types="vite/client" />
 /// <reference types="vite-svg-loader" />
-import { ObjectDirective } from 'vue'
-import { FormatType } from './directives'
 
 declare module '*.vue' {
   import { DefineComponent } from 'vue'
@@ -31,9 +29,3 @@ interface ImportMetaEnv {
 interface ImportMeta {
   readonly env: ImportMetaEnv
 }
-
-declare module 'vue' {
-  interface ComponentCustomProperties {
-    vFormat: ObjectDirective<HTMLElement, FormatType>
-  }
-}

+ 8 - 0
src/typings.d.ts

@@ -1,4 +1,6 @@
 // 全局要用的类型放到这里
+import { ObjectDirective } from 'vue'
+import { FormatType } from './directives/format'
 
 declare global {
   type IResData<T> = {
@@ -17,4 +19,10 @@ declare global {
   }
 }
 
+declare module '@vue/runtime-core' {
+  interface ComponentCustomProperties {
+    vFormat: (el: HTMLElement, { value }: DirectiveBinding<FormatType>) => void
+  }
+}
+
 export {} // 防止模块污染