import * as Koa from 'koa'
const app = new Koa()
app.a = 10
app.children.hong = 'hong'
我想给koa扩展这两个属性,该怎么修改呢
我试过以下方法 不管用。
1.
import * as Koa from 'koa'
declare module 'koa' {
interface Application {
a: number,
children: {
hong: string
}
}
}
2.
import * as Koa from 'koa'
declare module 'koa' {
type a = number
type children = any
}
3.
import * as KoaApplication from 'koa'
declare module 'koa' {
export class Application {
a: any
children: any
}
}
4.
import KoaApplication = require('koa')
declare module 'koa' {
export class Application extends KoaApplication{
a: any
children: any
}
}
我直接在@type下面的class Application 里面添加属性,就可以顺利编译过。但是在外面我就不知道怎么给他添加了。因为他里面是class ,我不太清楚如何在外面继承里面的class Application 然后在定义新属性。上面第4种方法尝试了,却不管用
求大神解答?