[英]TypeScript compile error: Array.map(callback) expression is not callable
以下是用 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 报告不是 callbale。
我不确定为什么会这样,但你可以试试这个:
var myfiles = JSON.parse(JSON.stringify(req.files))
它看起来像这样:
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 = JSON.parse(JSON.stringify(req.files))
console.log("myfiles", myfiles);
myfiles.map( function(item, index) {
//return checkExisting(col, item)
})
}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.