mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 12:42:58 +08:00
'vue-router' provides its own types (#14099)
This commit is contained in:
@@ -275,6 +275,12 @@
|
||||
"typingsPackageName": "scanf",
|
||||
"sourceRepoURL": "https://github.com/Lellansin/node-scanf",
|
||||
"asOfVersion": "0.7.3"
|
||||
},
|
||||
{
|
||||
"libraryName": "vue-router",
|
||||
"typingsPackageName": "vue-router",
|
||||
"sourceRepoURL": "https://github.com/vuejs/vue-router",
|
||||
"asOfVersion": "2.0.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
89
vue-router/index.d.ts
vendored
89
vue-router/index.d.ts
vendored
@@ -1,89 +0,0 @@
|
||||
// Type definitions for vue-router 0.7.10
|
||||
// Project: https://github.com/vuejs/vue-router
|
||||
// Definitions by: kaorun343 <https://github.com/kaorun343>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="vue" />
|
||||
|
||||
declare namespace vuejs {
|
||||
|
||||
interface Transition<RootVueApp, FromParams, FromQuery, ToParams, ToQuery> {
|
||||
from: $route<RootVueApp, FromParams, FromQuery>;
|
||||
to: $route<RootVueApp, ToParams, ToQuery>;
|
||||
next(data?: any): void;
|
||||
abort(reason?: any): void;
|
||||
redirect(path: string): void;
|
||||
}
|
||||
|
||||
interface RouterOption {
|
||||
hashbang?: boolean;
|
||||
history?: boolean;
|
||||
abstract?: boolean;
|
||||
root?: string;
|
||||
linkActiveClass?: string;
|
||||
saveScrollPosition?: boolean;
|
||||
transitionOnLoad?: boolean;
|
||||
suppressTransitionError?: boolean;
|
||||
}
|
||||
|
||||
interface RouterStatic {
|
||||
new <RootVueApp>(option?: RouterOption): Router<RootVueApp>;
|
||||
}
|
||||
|
||||
interface RouteMapObject {
|
||||
component: any;
|
||||
subRoutes?: { [key: string]: RouteMapObject };
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface Router<RootVueApp> {
|
||||
|
||||
app: RootVueApp;
|
||||
mode: string;
|
||||
|
||||
start(App: any, el: string | Element): void;
|
||||
stop(): void;
|
||||
map(routeMap: { [path: string]: RouteMapObject }): void;
|
||||
on(path: string, config: Object): void;
|
||||
go(path: string | Object): void;
|
||||
replace(path: string): void;
|
||||
redirect(redirectMap: Object): void;
|
||||
alias(aliasMap: Object): void;
|
||||
beforeEach<FP, FQ, TP, TQ>(hook: (transition: Transition<RootVueApp, FP, FQ, TP, TQ>) => any): void;
|
||||
afterEach<FP, FQ, TP, TQ>(hook: (transition: Transition<RootVueApp, FP, FQ, TP, TQ>) => any): void;
|
||||
}
|
||||
|
||||
interface $route<RootVueApp, Params, Query> {
|
||||
path: string;
|
||||
params: Params;
|
||||
query: Query;
|
||||
router: Router<RootVueApp>;
|
||||
matched: string[];
|
||||
name: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface TransitionHook<Root, FP, FQ, TP, TQ> {
|
||||
data?(transition?: Transition<Root, FP, FQ, TP, TQ>): PromiseLike<any> | void;
|
||||
activate?(transition?: Transition<Root, FP, FQ, TP, TQ>): PromiseLike<any> | void;
|
||||
deactivate?(transition?: Transition<Root, FP, FQ, TP, TQ>): PromiseLike<any> | void;
|
||||
canActivate?(transition?: Transition<Root, FP, FQ, TP, TQ>): PromiseLike<any> | boolean | void;
|
||||
canDeactivate?(transition?: Transition<Root, FP, FQ, TP, TQ>): PromiseLike<any> | boolean | void;
|
||||
canReuse?: boolean | ((transition: Transition<Root, FP, FQ, TP, TQ>) => boolean);
|
||||
}
|
||||
|
||||
interface Vue {
|
||||
$route: vuejs.$route<any, any, any>;
|
||||
$router: vuejs.Router<any>;
|
||||
}
|
||||
|
||||
interface ComponentOption {
|
||||
route?: vuejs.TransitionHook<any, any, any, any, any>;
|
||||
}
|
||||
}
|
||||
|
||||
declare var VueRouter: vuejs.RouterStatic;
|
||||
|
||||
declare module "vue-router" {
|
||||
export = VueRouter;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"@types/vue": "^1.0.31"
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"vue-router-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
|
||||
|
||||
Vue.use(VueRouter);
|
||||
|
||||
namespace TestBasic {
|
||||
"use strict";
|
||||
|
||||
var Foo = Vue.extend({
|
||||
template: "<p>This is foo!</p>",
|
||||
route: {
|
||||
canActivate(transition: vuejs.Transition<any, any, any, any, any>) {
|
||||
return true;
|
||||
},
|
||||
activate: function() {
|
||||
var p: PromiseLike<any>;
|
||||
return p;
|
||||
},
|
||||
deactivate: function(transition: vuejs.Transition<any, any, any, any, any>) {
|
||||
transition.next();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var Bar = Vue.extend({
|
||||
template: "<p>This is bar!</p>"
|
||||
});
|
||||
|
||||
var App = Vue.extend({});
|
||||
var app = new App();
|
||||
app.$on("some event", function() {
|
||||
var name: string = app.$route.name;
|
||||
});
|
||||
|
||||
var router = new VueRouter<typeof App.prototype>();
|
||||
|
||||
router.map({
|
||||
"/foo": {
|
||||
component: Foo
|
||||
},
|
||||
"/bar": {
|
||||
component: Bar
|
||||
}
|
||||
});
|
||||
|
||||
router.start(App, "#app");
|
||||
}
|
||||
|
||||
namespace TestAdvanced {
|
||||
"use strict";
|
||||
|
||||
namespace App {
|
||||
|
||||
export class App extends Vue {
|
||||
authenticating: boolean;
|
||||
|
||||
data() {
|
||||
return {
|
||||
authenticating: false
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Inbox {
|
||||
export class Index extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
namespace RouteConfig {
|
||||
export function configRouter(router: vuejs.Router<App.App>) {
|
||||
router.map({
|
||||
"/about": {
|
||||
component: {},
|
||||
auth: false
|
||||
},
|
||||
"*": {
|
||||
component: {}
|
||||
}
|
||||
});
|
||||
|
||||
router.redirect({
|
||||
"/info": "/about",
|
||||
"/hello/:userId": "/user/:userId"
|
||||
});
|
||||
|
||||
router.beforeEach((transition) => {
|
||||
if (transition.to.path === "/forbidden") {
|
||||
router.app.authenticating = true;
|
||||
setTimeout(() => {
|
||||
router.app.authenticating = false;
|
||||
alert("");
|
||||
transition.abort();
|
||||
}, 3000);
|
||||
} else {
|
||||
transition.next();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
import configRouter = RouteConfig.configRouter;
|
||||
|
||||
const router = new VueRouter<App.App>({
|
||||
history: true,
|
||||
saveScrollPosition: true
|
||||
});
|
||||
|
||||
configRouter(router);
|
||||
router.start(App, "#app");
|
||||
}
|
||||
Reference in New Issue
Block a user