Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typings): adapt to the new Vue typings #1685

Merged
merged 6 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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