From fe2b27ffb98932ec8e822bd88b4de1666810521c Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 10 Jan 2019 22:44:55 -0500 Subject: [PATCH] types: typing for Vue.observable --- flow/global-api.js | 2 ++ src/core/global-api/index.js | 2 +- types/test/vue-test.ts | 3 +++ types/vue.d.ts | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) 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; }