0
命名空间,我喜欢写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使其作品?