我在nodejs / express项目的上下文中从1.8.10 ts编译器中得到此错误:
错误:(17,23)TS2345:类型' typeof的参数 " /用户/ ME /文档/ Apps_And_Sites / Js_Apps /网站/应用/目录/ directory_contr ...' 不能分配给'路由器'类型的参数。财产' param'是 缺少类型' typeof " /用户/ ME /文档/ Apps_And_Sites / Js_Apps /网站/应用/目录/ directory_contr ...'
这是控制器文件:
Import * as express from "express"
import * as directory_models from "./directory_models"
import * as forms from "formidable"
let directory_router = express.Router() // HERE /////////
// GET
directory_router.get("/list", function (req, res) {
function callback (err, data) { // function definition
res.render("directory_views.ejs", {datatest: data})
}
directory_models.read(
`SELECT link_title
FROM
links`,
callback)
})
// POST
directory_router.route("/create")
// Display form page
.get(function (req, res) {
res.render("directory_post.ejs")
})
// Process form
.post(function (req, res) {
let form = new forms.IncomingForm()
form.parse(req, function (err, fields, files) {
directory_models.create(fields)
})
res.render("directory_post.ejs")
})
module.exports = directory_router
以下是网络应用的输入文件:
import * as express from "express"
import * as lodash from "lodash"
import * as directory from "./apps/directory/directory_controller"
// Non require variables
let app = express()
let port = process.env.PORT || 3002
import * as forms from "formidable"
app.use("/directory", directory) // ERROR HERE ////////
app.set("views", [__dirname + "/apps/directory/views/", "views"])
app.set("view engine", "ejs")
app.listen(port, function () {
console.log("Server is listening on port:" + port)
})
它并没有阻止项目正常工作,但我仍然想了解并摆脱这个错误。你知道吗?
答案 0 :(得分:0)
module.exports = directory_router
你应该这样做:
export = directory_controller