Skip to content

Commit fe2b27f

Browse files
committed
types: typing for Vue.observable
1 parent 142cf6c commit fe2b27f

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

flow/global-api.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ declare interface GlobalAPI {
1616
component: (id: string, def?: Class<Component> | Object) => Class<Component>;
1717
filter: (id: string, def?: Function) => Function | void;
1818

19+
observable: <T>(value: T) => T;
20+
1921
// allow dynamic method registration
2022
[key: string]: any
2123
};

src/core/global-api/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function initGlobalAPI (Vue: GlobalAPI) {
4646
Vue.nextTick = nextTick
4747

4848
// 2.6 explicit observable API
49-
Vue.observable = (obj: any): any => {
49+
Vue.observable = <T>(obj: T): T => {
5050
observe(obj)
5151
return obj
5252
}

types/test/vue-test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,6 @@ declare function decorate<VC extends typeof Vue>(v: VC): VC;
200200
class Decorated extends Vue {
201201
a = 123;
202202
}
203+
204+
const obj = Vue.observable({ a: 1 })
205+
obj.a++

types/vue.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ export interface VueConstructor<V extends Vue = Vue> {
119119
staticRenderFns: (() => VNode)[];
120120
};
121121

122+
observable<T>(obj: T): T;
123+
122124
config: VueConfiguration;
123125
}
124126

0 commit comments

Comments
 (0)