Repository: vuejs/vue
Pull request: fix(types): fix global namespace declaration for UMD bundle

<!--
Please make sure to read the Pull Request Guidelines:
https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md#pull-request-guidelines
-->

<!-- PULL REQUEST TEMPLATE -->
<!-- (Update "[ ]" to "[x]" to check a box) -->

**What kind of change does this PR introduce?** (check at least one)

- [x] Bugfix
- [ ] Feature
- [ ] Code style update
- [ ] Refactor
- [ ] Build-related changes
- [ ] Other, please describe:

**Does this PR introduce a breaking change?** (check one)

- [ ] Yes
- [x] No

If yes, please describe the impact and migration path for existing applications:

**The PR fulfills these requirements:**

- [x] It's submitted to the `dev` branch for v2.x (or to a previous version branch), _not_ the `master` branch
- [ ] When resolving a specific issue, it's referenced in the PR's title (e.g. `fix #xxx[,#xxx]`, where "xxx" is the issue number)
- [x] All tests are passing: https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md#development-setup
- [x] New/updated tests are included

If adding a **new feature**, the PR's description includes:
- [ ] A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

**Other information:**

In the current declaration, `index.d.ts` has `export as namespace Vue` which exposes all exported types in `index.d.ts` in global namespace. So the user can access them by just writing like `Vue.ComponentOptions` without import statement.

But this declaration is actually not correct because the `Vue` constructor type is declared under `default` which is correct in ESModule bundle but UMD bundle.

```ts
new Vue({}) // This provides compilation error in current type.

new Vue.default({}) // No compilation error.
```

To declare Vue constructor as just `Vue` in global namespace, we need to write `export as namespace Vue` with a common js export. So I've add `umd.d.ts` and do that in that file.

Changed files:
filename: types/index.d.ts
patch: @@ -1,9 +1,8 @@
 import { Vue } from "./vue";
+import "./umd";
 
 export default Vue;
 
-export as namespace Vue;
-
 export {
   CreateElement,
   VueConstructor

filename: types/test/tsconfig.json
patch: @@ -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
 }

filename: types/test/umd-test.ts
patch: @@ -0,0 +1,7 @@
+const vm = new Vue({
+  template: "<div>hi</div>"
+});
+
+const options: Vue.ComponentOptions<Vue> = {
+  template: "<div>test</div>"
+};

filename: types/umd.d.ts
patch: @@ -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;