egg icon indicating copy to clipboard operation
egg copied to clipboard

[Feature Request] egg-passport 的 index.d.ts 添加支持回调函数

Open HowGraceU opened this issue 6 years ago • 1 comments

Background

我在使用 ctx.app.passport.authenticate 时,翻阅了passport的文档的时候发现可以自定义回调函数,而我在 ts 模板中使用回调函数的时候,代码可以跑通,但是 ts 编译报错,因为 egg-passport 的 index.d.ts 里面定义的第二个参数只能传 AuthenticateOptions 类型

interface EggPassport extends Authenticator {
  authenticate<AuthenticateRet = any>(strategy: string | string[]): AuthenticateRet;
  authenticate<AuthenticateRet = any>(strategy: string | string[], options: AuthenticateOptions): AuthenticateRet;
  ...
}

Proposal

希望能多加一个函数重载以支持在 ts 中使用回调函数

interface EggPassport extends Authenticator {
  authenticate<AuthenticateRet = any>(strategy: string | string[]): AuthenticateRet;
  authenticate<AuthenticateRet = any>(strategy: string | string[], options: AuthenticateOptions): AuthenticateRet;
  authenticate<AuthenticateRet = any>(strategy: string | string[], callback: function): AuthenticateRet;
  ...
}

HowGraceU avatar Jan 03 '20 15:01 HowGraceU

PR is welcome :)

hyj1991 avatar Jan 04 '20 03:01 hyj1991