【发布时间】:2020-06-08 16:10:15
【问题描述】:
以下是一个用 Typescript 编写的 Node.js API,
app.post('/photos/upload', upload.array('photos', 12), async (req, res) => {
var response = { }
var list = []
try {
const col = await loadCollection(COLLECTION_NAME, db)
var myfiles = req.files
console.log("myfiles", myfiles);
myfiles.map( function(item, index) {
//return checkExisting(col, item)
})
}}
并在myfiles.map(function(item, index) { 行收到以下打字稿错误
index.ts:77:13 - error TS2349: This expression is not callable.
Not all constituents of type 'File[] | (<U>(callbackfn: (value: File, index: number, array: File[]) => U, thisArg?: any) => U[])' are callable.
Type 'File[]' has no call signatures.
77 myfiles.map( function(item, index) {
~~~
由于我对 Typescript 完全陌生,不确定是什么问题,myfiles.map(callback) 是数组上的有效可调用方法,所以为什么 typescript 报告不调用。
【问题讨论】:
-
在错误行之前输入:console.log (typeof myfiles) 并在此处输入结果
-
如果添加
async (req: {files: any[]}, res)会怎样 -
关键是看看
checkExisting做了什么。看看这个。 stackoverflow.com/a/51573837/17447 -
@naveen 已经禁用
checkExisting并尝试但同样的错误。checkExisting一个函数 -
@AksJacoves 这是一个打字稿编译时错误,所以
console.log没有被执行。我尝试过这个。此外,我在终端看到npm ERR! node-tutorial@1.0.0 prestart:tsc`` 和Failed at the node-tutorial@1.0.0 prestart script.
标签: javascript node.js typescript