Skip to content

Commit

Permalink
feat(typings): adapt to the new Vue typings (#1685)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: It is no longer compatible with the old Vue typings
  • Loading branch information
ktsn authored and yyx990803 committed Oct 11, 2017
1 parent 798e968 commit 8855e36
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 38 deletions.
4 changes: 1 addition & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"selenium-server": "^2.53.1",
"typescript": "^2.5.3",
"uglify-js": "^3.1.3",
"vue": "^2.4.4",
"vue": "github:vuejs/vue#dev",
"vue-loader": "^13.3.0",
"vue-template-compiler": "^2.4.4",
"webpack": "^3.7.1",
Expand Down
31 changes: 13 additions & 18 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import "./vue";
import * as R from "./router";
import { VueRouter } from "./router";

// `VueRouter` in `export = VueRouter` must be a namespace
// All available types are exported via this namespace
declare namespace VueRouter {
export type RouterMode = R.RouterMode;
export type RawLocation = R.RawLocation;
export type RedirectOption = R.RedirectOption;
export type RouterOptions = R.RouterOptions;
export type RouteConfig = R.RouteConfig;
export type RouteRecord = R.RouteRecord;
export type Location = R.Location;
export type Route = R.Route;
export type NavigationGuard = R.NavigationGuard;
}
export default VueRouter;

// TS cannot merge imported class with namespace, declare a subclass to bypass
declare class VueRouter extends R.VueRouter {}

export = VueRouter;
export {
RouterMode,
RawLocation,
RedirectOption,
RouterOptions,
RouteConfig,
RouteRecord,
Location,
Route,
NavigationGuard
} from "./router";
5 changes: 2 additions & 3 deletions types/router.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Vue = require("vue");
import { ComponentOptions, PluginFunction, AsyncComponent } from "vue";
import Vue, { ComponentOptions, PluginFunction, AsyncComponent } from "vue";

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

declare class VueRouter {
export declare class VueRouter {
constructor (options?: RouterOptions);

app: Vue;
Expand Down
5 changes: 2 additions & 3 deletions types/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Vue = require("vue");
import { ComponentOptions, AsyncComponent } from "vue";
import Vue, { ComponentOptions, AsyncComponent } from "vue";

import VueRouter = require("../index");
import VueRouter from "../index";
import { Route, RouteRecord, RedirectOption } from "../index";

Vue.use(VueRouter);
Expand Down
6 changes: 3 additions & 3 deletions types/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"noImplicitAny": true,
"strictNullChecks": true,
"module": "es2015",
"moduleResolution": "node",
"strict": true,
"noEmit": true,
"lib": [
"es5",
Expand Down
4 changes: 0 additions & 4 deletions types/typings.json

This file was deleted.

5 changes: 2 additions & 3 deletions types/vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
* Augment the typings of Vue.js
*/

import Vue = require("vue");
import VueRouter = require("./index");
import { Route, RawLocation, NavigationGuard } from "./index";
import Vue from "vue";
import VueRouter, { Route, RawLocation, NavigationGuard } from "./index";

declare module "vue/types/vue" {
interface Vue {
Expand Down

0 comments on commit 8855e36

Please sign in to comment.