import Koa from "koa"
import Router from "koa-router"
import logger from "koa-logger"
import json from "koa-json"
const app = new Koa()
const router = new Router()
router.get("/",async(ctx: any,next: any)=>{
ctx.body = {
meg:"Hello world"
}
await next
})
app.use(logger())
app.use(json())
app.use(router.routes()).use(router.allowedMethods())
app.listen(3000,()=>console.log("app is running at 3000"))
Actually,before this ,when I run npm run build,I got error src/index.ts:2:20 – error TS2307: Cannot find module ‘koa-router’. I write koa-router.d.ts myself, but I don’t think it’s a great idea, How do you guys resolve?
>Solution :
You say you wrote koa-router.d.ts yourself, but npm shows that the koa-router module has type declarations.
Remove koa-router and re-install it (and its types) using
npm uninstall koa-router;
npm install koa-router @types/koa-router;