diff --git a/index.d.ts b/index.d.ts index a32897d10c..dedf0cc4f9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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); } @@ -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 diff --git a/test/fixtures/apps/app-ts/app/controller/foo.ts b/test/fixtures/apps/app-ts/app/controller/foo.ts index 9a9275f4e3..c425f31645 100644 --- a/test/fixtures/apps/app-ts/app/controller/foo.ts +++ b/test/fixtures/apps/app-ts/app/controller/foo.ts @@ -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) { diff --git a/test/fixtures/apps/app-ts/app/extend/context.ts b/test/fixtures/apps/app-ts/app/extend/context.ts new file mode 100644 index 0000000000..d4786639db --- /dev/null +++ b/test/fixtures/apps/app-ts/app/extend/context.ts @@ -0,0 +1,7 @@ +import { Context } from 'egg'; + +export default { + test(this: Context) { + return this.url; + }, +} \ No newline at end of file diff --git a/test/fixtures/apps/app-ts/app/extend/helper.ts b/test/fixtures/apps/app-ts/app/extend/helper.ts new file mode 100644 index 0000000000..32e799ab47 --- /dev/null +++ b/test/fixtures/apps/app-ts/app/extend/helper.ts @@ -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()); + } +} \ No newline at end of file diff --git a/test/fixtures/apps/app-ts/app/extend/index.d.ts b/test/fixtures/apps/app-ts/app/extend/index.d.ts new file mode 100644 index 0000000000..0fa65cb394 --- /dev/null +++ b/test/fixtures/apps/app-ts/app/extend/index.d.ts @@ -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 { } +}