Skip to content

Commit 8855e36

Browse files
ktsnyyx990803
authored andcommitted
feat(typings): adapt to the new Vue typings (#1685)
BREAKING CHANGE: It is no longer compatible with the old Vue typings
1 parent 798e968 commit 8855e36

File tree

8 files changed

+24
-38
lines changed

8 files changed

+24
-38
lines changed

package-lock.json

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"selenium-server": "^2.53.1",
7171
"typescript": "^2.5.3",
7272
"uglify-js": "^3.1.3",
73-
"vue": "^2.4.4",
73+
"vue": "github:vuejs/vue#dev",
7474
"vue-loader": "^13.3.0",
7575
"vue-template-compiler": "^2.4.4",
7676
"webpack": "^3.7.1",

types/index.d.ts

+13-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
import "./vue";
2-
import * as R from "./router";
2+
import { VueRouter } from "./router";
33

4-
// `VueRouter` in `export = VueRouter` must be a namespace
5-
// All available types are exported via this namespace
6-
declare namespace VueRouter {
7-
export type RouterMode = R.RouterMode;
8-
export type RawLocation = R.RawLocation;
9-
export type RedirectOption = R.RedirectOption;
10-
export type RouterOptions = R.RouterOptions;
11-
export type RouteConfig = R.RouteConfig;
12-
export type RouteRecord = R.RouteRecord;
13-
export type Location = R.Location;
14-
export type Route = R.Route;
15-
export type NavigationGuard = R.NavigationGuard;
16-
}
4+
export default VueRouter;
175

18-
// TS cannot merge imported class with namespace, declare a subclass to bypass
19-
declare class VueRouter extends R.VueRouter {}
20-
21-
export = VueRouter;
6+
export {
7+
RouterMode,
8+
RawLocation,
9+
RedirectOption,
10+
RouterOptions,
11+
RouteConfig,
12+
RouteRecord,
13+
Location,
14+
Route,
15+
NavigationGuard
16+
} from "./router";

types/router.d.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import Vue = require("vue");
2-
import { ComponentOptions, PluginFunction, AsyncComponent } from "vue";
1+
import Vue, { ComponentOptions, PluginFunction, AsyncComponent } from "vue";
32

43
type Component = ComponentOptions<Vue> | typeof Vue | AsyncComponent;
54
type Dictionary<T> = { [key: string]: T };
@@ -13,7 +12,7 @@ export type NavigationGuard = (
1312
next: (to?: RawLocation | false | ((vm: Vue) => any) | void) => void
1413
) => any
1514

16-
declare class VueRouter {
15+
export declare class VueRouter {
1716
constructor (options?: RouterOptions);
1817

1918
app: Vue;

types/test/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import Vue = require("vue");
2-
import { ComponentOptions, AsyncComponent } from "vue";
1+
import Vue, { ComponentOptions, AsyncComponent } from "vue";
32

4-
import VueRouter = require("../index");
3+
import VueRouter from "../index";
54
import { Route, RouteRecord, RedirectOption } from "../index";
65

76
Vue.use(VueRouter);

types/test/tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4-
"module": "commonjs",
5-
"noImplicitAny": true,
6-
"strictNullChecks": true,
4+
"module": "es2015",
5+
"moduleResolution": "node",
6+
"strict": true,
77
"noEmit": true,
88
"lib": [
99
"es5",

types/typings.json

-4
This file was deleted.

types/vue.d.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
* Augment the typings of Vue.js
33
*/
44

5-
import Vue = require("vue");
6-
import VueRouter = require("./index");
7-
import { Route, RawLocation, NavigationGuard } from "./index";
5+
import Vue from "vue";
6+
import VueRouter, { Route, RawLocation, NavigationGuard } from "./index";
87

98
declare module "vue/types/vue" {
109
interface Vue {

0 commit comments

Comments
 (0)