I am starting to develop applications using typescript. I had come across a code snippet where I couldn't understand the line marked within ** <> **. Anybody please throw some light.
export const applyRoutes = (routes: Route[], router: Router) => {
for (const route of routes) {
const { method, path, handler } = route;
**(router as any)[method](path, handler);**
}
};
Regards, Karthikeyan R
(router as any)
tells typescript that regardless of what it thinks the types are, it should treat router
as having type any
. In other words, it turns off type checking.
router[method](path, handler)
means "access the method
property on router
, then call it passing in path
and handler
".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.