如何解决有没有一种方法可以只为第二个泛型传递值,而不能为打字稿中具有默认值的第一个传递值?
Koa中间件类型定义
// @types/koa
type Middleware<StateT = DefaultState,CustomT = DefaultContext> = compose.Middleware<
ParameterizedContext<StateT,CustomT>
>;
期望
// src/middleware/cookie.ts
import { ExtendableContext,Middleware } from "koa";
type CookieContext = ExtendableContext & {
cookie: string;
}
const parseCookieMiddleware: Middleware</*wanna skip passing generic here to use default type(DefaultState)*/,CookieContext> = async (ctx,next) => {
//parse cookie here
await next();
};
我可以通过DefaultState或创建wrapdMiddlewareType,
但是Koa类型定义为我们提供了默认值。
所以我只想跳过不必要的步骤。
感谢您的阅读。
祝你有美好的一天!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。