【发布时间】:2017-08-20 02:36:30
【问题描述】:
我喜欢为https://github.com/LionC/express-basic-auth写一个index.d.ts文件
但我不知何故陷入了如何在选项对象中声明回调的类型。
declare module "express-basic-auth" {
import {Handler, Request} from "express";
function ExpressBasicAuthorizer(username: string, password: string): boolean;
function ExpressBasicAuthResponseHandler(req: Request): string|object;
interface ExpressBasicAuthUsers {
[username: string]: string;
}
interface ExpressBasicAuthOptions {
challenge?: boolean;
users?: ExpressBasicAuthUsers; // does not only allow string:string but other ex. string: number too
authorizer?: ExpressBasicAuthorizer; // *does not work*
authorizeAsync?: boolean;
unauthorizedResponse?: ExpressBasicAuthResponseHandler|string|object; // *does not work*
realm?: ExpressBasicAuthResponseHandler|string; // *does not work*
}
function expressBasicAuth(options?:ExpressBasicAuthOptions): Handler;
export = expressBasicAuth;
}
我得到:错误 TS2304:找不到名称“ExpressBasicAuthorizer”
如何声明 ExpressBasicAuthorizer 和 ExpressBasicAuthResponseHandler 以使其正常工作?
【问题讨论】:
标签: typescript typescript-types