[英]Typescript syntax related
我开始使用打字稿开发应用程序。 我遇到了一个代码片段,其中我无法理解 ** <> ** 中标记的行。 任何人请投点灯。
export const applyRoutes = (routes: Route[], router: Router) => {
for (const route of routes) {
const { method, path, handler } = route;
**(router as any)[method](path, handler);**
}
};
问候, Karthikeyan R
(router as any)
告诉打字稿,无论它认为类型是什么,它都应该将router
视为具有类型any
。 换句话说,它关闭了类型检查。
router[method](path, handler)
表示“访问router
上的method
属性,然后调用它传入path
和handler
”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.