فهرست منبع

types: typing for Vue.observable

Evan You 7 سال پیش
والد
کامیت
fe2b27ffb9
4فایلهای تغییر یافته به همراه8 افزوده شده و 1 حذف شده
  1. 2 0
      flow/global-api.js
  2. 1 1
      src/core/global-api/index.js
  3. 3 0
      types/test/vue-test.ts
  4. 2 0
      types/vue.d.ts

+ 2 - 0
flow/global-api.js

@@ -16,6 +16,8 @@ declare interface GlobalAPI {
   component: (id: string, def?: Class<Component> | Object) => Class<Component>;
   filter: (id: string, def?: Function) => Function | void;
 
+  observable: <T>(value: T) => T;
+
   // allow dynamic method registration
   [key: string]: any
 };

+ 1 - 1
src/core/global-api/index.js

@@ -46,7 +46,7 @@ export function initGlobalAPI (Vue: GlobalAPI) {
   Vue.nextTick = nextTick
 
   // 2.6 explicit observable API
-  Vue.observable = (obj: any): any => {
+  Vue.observable = <T>(obj: T): T => {
     observe(obj)
     return obj
   }

+ 3 - 0
types/test/vue-test.ts

@@ -200,3 +200,6 @@ declare function decorate<VC extends typeof Vue>(v: VC): VC;
 class Decorated extends Vue {
   a = 123;
 }
+
+const obj = Vue.observable({ a: 1 })
+obj.a++

+ 2 - 0
types/vue.d.ts

@@ -119,6 +119,8 @@ export interface VueConstructor<V extends Vue = Vue> {
     staticRenderFns: (() => VNode)[];
   };
 
+  observable<T>(obj: T): T;
+
   config: VueConfiguration;
 }