diff --git a/flow/global-api.js b/flow/global-api.js index eab244c2..0ce54fda 100644 --- a/flow/global-api.js +++ b/flow/global-api.js @@ -16,6 +16,8 @@ declare interface GlobalAPI { component: (id: string, def?: Class | Object) => Class; filter: (id: string, def?: Function) => Function | void; + observable: (value: T) => T; + // allow dynamic method registration [key: string]: any }; diff --git a/src/core/global-api/index.js b/src/core/global-api/index.js index 2bca92bb..b3387a89 100644 --- a/src/core/global-api/index.js +++ b/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 = (obj: T): T => { observe(obj) return obj } diff --git a/types/test/vue-test.ts b/types/test/vue-test.ts index 40ded2d2..57cafc47 100644 --- a/types/test/vue-test.ts +++ b/types/test/vue-test.ts @@ -200,3 +200,6 @@ declare function decorate(v: VC): VC; class Decorated extends Vue { a = 123; } + +const obj = Vue.observable({ a: 1 }) +obj.a++ diff --git a/types/vue.d.ts b/types/vue.d.ts index 2098a694..1b92e666 100644 --- a/types/vue.d.ts +++ b/types/vue.d.ts @@ -119,6 +119,8 @@ export interface VueConstructor { staticRenderFns: (() => VNode)[]; }; + observable(obj: T): T; + config: VueConfiguration; }