Skip to content

Commit

Permalink
fix: helper type (#3483)
Browse files Browse the repository at this point in the history
  • Loading branch information
whxaxes authored and atian25 committed Feb 22, 2019
1 parent 969c3dd commit ac7e9a6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
12 changes: 6 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,27 @@ declare module 'egg' {
/**
* request context
*/
ctx: Context;
protected ctx: Context;

/**
* Application
*/
app: Application;
protected app: Application;

/**
* Application config object
*/
config: EggAppConfig;
protected config: EggAppConfig;

/**
* service
*/
service: IService;
protected service: IService;

/**
* logger
*/
logger: EggLogger;
protected logger: EggLogger;

constructor(ctx: Context);
}
Expand Down Expand Up @@ -937,7 +937,7 @@ declare module 'egg' {

export interface IMiddleware extends PlainObject { } // tslint:disable-line

export interface IHelper extends PlainObject {
export interface IHelper extends PlainObject, BaseContextClass {
/**
* Generate URL path(without host) for route. Takes the route name and a map of named params.
* @method Helper#pathFor
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/apps/app-ts/app/controller/foo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class FooController extends Controller {
async getData() {
try {
this.ctx.logger.info('getData');
this.ctx.helper.test();
this.ctx.body = await this.ctx.service.foo.bar();
this.ctx.proxy.foo.bar();
} catch (e) {
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/apps/app-ts/app/extend/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Context } from 'egg';

export default {
test(this: Context) {
return this.url;
},
}
11 changes: 11 additions & 0 deletions test/fixtures/apps/app-ts/app/extend/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IHelper } from 'egg';

export default {
test(this: IHelper) {
this.test2();
},

test2(this: IHelper) {
this.ctx.logger.info(this.ctx.test());
}
}
9 changes: 9 additions & 0 deletions test/fixtures/apps/app-ts/app/extend/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ExtendHelper from './helper';
import ExtendContext from './context';

declare module 'egg' {
type ExtendHelperType = typeof ExtendHelper;
type ExtendContextType = typeof ExtendContext;
interface IHelper extends ExtendHelperType { }
interface Context extends ExtendContextType { }
}

0 comments on commit ac7e9a6

Please sign in to comment.