mirror of
https://github.com/eggjs/egg.git
synced 2024-12-04 07:14:30 +00:00
fix(types): app.router.url params should be optional (#5132)
add missing pathFor and methods defines
This commit is contained in:
parent
2c79734d51
commit
dda6bb3674
11
index.d.ts
vendored
11
index.d.ts
vendored
@ -546,7 +546,7 @@ declare module 'egg' {
|
||||
headers: { [key: string]: string };
|
||||
}
|
||||
|
||||
export interface Router extends KoaRouter<any, Context> {
|
||||
export interface Router extends Omit<KoaRouter<any, Context>, 'url'> {
|
||||
/**
|
||||
* restful router api
|
||||
*/
|
||||
@ -554,7 +554,7 @@ declare module 'egg' {
|
||||
|
||||
/**
|
||||
* @param {String} name - Router name
|
||||
* @param {Object} params - more parameters
|
||||
* @param {Object} [params] - more parameters
|
||||
* @example
|
||||
* ```js
|
||||
* router.url('edit_post', { id: 1, name: 'foo', page: 2 })
|
||||
@ -565,7 +565,12 @@ declare module 'egg' {
|
||||
* @return {String} url by path name and query params.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
url(name: string, params: any): any;
|
||||
url(name: string, params?: any): string;
|
||||
/**
|
||||
* Alias for the url method
|
||||
*/
|
||||
pathFor(name: string, params?: any): string;
|
||||
methods: string[];
|
||||
}
|
||||
|
||||
export interface EggApplication extends EggCoreBase<EggAppConfig> { // tslint:disable-line
|
||||
|
||||
@ -30,6 +30,13 @@ export default class FooController extends Controller {
|
||||
this.fooLogger = ctx.getLogger('foo');
|
||||
assert(ctx.app.ctxStorage);
|
||||
assert(ctx.app.currentContext);
|
||||
|
||||
// router
|
||||
console.log(ctx.app.router.url('foo'));
|
||||
console.log(ctx.app.router.url('foo', {}));
|
||||
console.log(ctx.app.router.pathFor('foo'));
|
||||
console.log(ctx.app.router.pathFor('foo', {}));
|
||||
console.log(ctx.app.router.methods);
|
||||
}
|
||||
|
||||
async getData() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user