fix(types): app.router.url params should be optional (#5132)

add missing pathFor and methods defines
This commit is contained in:
fengmk2 2023-01-20 18:55:56 +08:00 committed by GitHub
parent 2c79734d51
commit dda6bb3674
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

11
index.d.ts vendored
View File

@ -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

View File

@ -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() {