Skip to content

Commit ab50e8e

Browse files
ktsnyyx990803
authored andcommittedApr 25, 2019
fix(types): fix global namespace declaration for UMD bundle (#9912)
1 parent 085d188 commit ab50e8e

File tree

4 files changed

+59
-13
lines changed

4 files changed

+59
-13
lines changed
 

‎types/index.d.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Vue } from "./vue";
2+
import "./umd";
23

34
export default Vue;
45

5-
export as namespace Vue;
6-
76
export {
87
CreateElement,
98
VueConstructor

‎types/test/tsconfig.json

+3-11
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,9 @@
1414
"vue": ["../index.d.ts"]
1515
}
1616
},
17-
"files": [
18-
"../index.d.ts",
19-
"../options.d.ts",
20-
"../plugin.d.ts",
21-
"../vnode.d.ts",
22-
"../vue.d.ts",
23-
"options-test.ts",
24-
"plugin-test.ts",
25-
"vue-test.ts",
26-
"augmentation-test.ts",
27-
"ssr-test.ts"
17+
"include": [
18+
"../*.d.ts",
19+
"*.ts"
2820
],
2921
"compileOnSave": false
3022
}

‎types/test/umd-test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const vm = new Vue({
2+
template: "<div>hi</div>"
3+
});
4+
5+
const options: Vue.ComponentOptions<Vue> = {
6+
template: "<div>test</div>"
7+
};

‎types/umd.d.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as V from "./index";
2+
import {
3+
DefaultData,
4+
DefaultProps,
5+
DefaultMethods,
6+
DefaultComputed,
7+
PropsDefinition
8+
} from "./options";
9+
10+
// Expose some types for backword compatibility...
11+
declare namespace Vue {
12+
// vue.d.ts
13+
export type CreateElement = V.CreateElement;
14+
export type VueConstructor<V extends Vue = Vue> = V.VueConstructor<V>;
15+
16+
// options.d.ts
17+
export type Component<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = V.Component<Data, Methods, Computed, Props>;
18+
export type AsyncComponent<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = V.AsyncComponent<Data, Methods, Computed, Props>;
19+
export type ComponentOptions<V extends Vue, Data=DefaultData<V>, Methods=DefaultMethods<V>, Computed=DefaultComputed, PropsDef=PropsDefinition<DefaultProps>, Props=DefaultProps> = V.ComponentOptions<V, Data, Methods, Computed, PropsDef, Props>;
20+
export type FunctionalComponentOptions<Props = DefaultProps, PropDefs = PropsDefinition<Props>> = V.FunctionalComponentOptions<Props, PropDefs>;
21+
export type RenderContext<Props=DefaultProps> = V.RenderContext<Props>;
22+
export type PropType<T> = V.PropType<T>;
23+
export type PropOptions<T=any> = V.PropOptions<T>;
24+
export type ComputedOptions<T> = V.ComputedOptions<T>;
25+
export type WatchHandler<T> = V.WatchHandler<T>;
26+
export type WatchOptions = V.WatchOptions;
27+
export type WatchOptionsWithHandler<T> = V.WatchOptionsWithHandler<T>;
28+
export type DirectiveFunction = V.DirectiveFunction;
29+
export type DirectiveOptions = V.DirectiveOptions;
30+
31+
// plugin.d.ts
32+
export type PluginFunction<T> = V.PluginFunction<T>;
33+
export type PluginObject<T> = V.PluginObject<T>;
34+
35+
// vnode.d.ts
36+
export type VNodeChildren = V.VNodeChildren;
37+
export type VNodeChildrenArrayContents = V.VNodeChildrenArrayContents;
38+
export type VNode = V.VNode;
39+
export type VNodeComponentOptions = V.VNodeComponentOptions;
40+
export type VNodeData = V.VNodeData;
41+
export type VNodeDirective = V.VNodeDirective;
42+
}
43+
44+
declare class Vue extends V.default {}
45+
46+
export = Vue;
47+
48+
export as namespace Vue;

0 commit comments

Comments
 (0)
Please sign in to comment.