Skip to content

Commit

Permalink
fix(types): fix global namespace declaration for UMD bundle (#9912)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn authored and yyx990803 committed Apr 25, 2019
1 parent 085d188 commit ab50e8e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
3 changes: 1 addition & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Vue } from "./vue";
import "./umd";

export default Vue;

export as namespace Vue;

export {
CreateElement,
VueConstructor
Expand Down
14 changes: 3 additions & 11 deletions types/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,9 @@
"vue": ["../index.d.ts"]
}
},
"files": [
"../index.d.ts",
"../options.d.ts",
"../plugin.d.ts",
"../vnode.d.ts",
"../vue.d.ts",
"options-test.ts",
"plugin-test.ts",
"vue-test.ts",
"augmentation-test.ts",
"ssr-test.ts"
"include": [
"../*.d.ts",
"*.ts"
],
"compileOnSave": false
}
7 changes: 7 additions & 0 deletions types/test/umd-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const vm = new Vue({
template: "<div>hi</div>"
});

const options: Vue.ComponentOptions<Vue> = {
template: "<div>test</div>"
};
48 changes: 48 additions & 0 deletions types/umd.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as V from "./index";
import {
DefaultData,
DefaultProps,
DefaultMethods,
DefaultComputed,
PropsDefinition
} from "./options";

// Expose some types for backword compatibility...
declare namespace Vue {
// vue.d.ts
export type CreateElement = V.CreateElement;
export type VueConstructor<V extends Vue = Vue> = V.VueConstructor<V>;

// options.d.ts
export type Component<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = V.Component<Data, Methods, Computed, Props>;
export type AsyncComponent<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = V.AsyncComponent<Data, Methods, Computed, Props>;
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>;
export type FunctionalComponentOptions<Props = DefaultProps, PropDefs = PropsDefinition<Props>> = V.FunctionalComponentOptions<Props, PropDefs>;
export type RenderContext<Props=DefaultProps> = V.RenderContext<Props>;
export type PropType<T> = V.PropType<T>;
export type PropOptions<T=any> = V.PropOptions<T>;
export type ComputedOptions<T> = V.ComputedOptions<T>;
export type WatchHandler<T> = V.WatchHandler<T>;
export type WatchOptions = V.WatchOptions;
export type WatchOptionsWithHandler<T> = V.WatchOptionsWithHandler<T>;
export type DirectiveFunction = V.DirectiveFunction;
export type DirectiveOptions = V.DirectiveOptions;

// plugin.d.ts
export type PluginFunction<T> = V.PluginFunction<T>;
export type PluginObject<T> = V.PluginObject<T>;

// vnode.d.ts
export type VNodeChildren = V.VNodeChildren;
export type VNodeChildrenArrayContents = V.VNodeChildrenArrayContents;
export type VNode = V.VNode;
export type VNodeComponentOptions = V.VNodeComponentOptions;
export type VNodeData = V.VNodeData;
export type VNodeDirective = V.VNodeDirective;
}

declare class Vue extends V.default {}

export = Vue;

export as namespace Vue;

0 comments on commit ab50e8e

Please sign in to comment.