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

fix: helper type #3483

Merged
merged 1 commit into from
Feb 22, 2019
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
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 { }
}